Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(servicecatalogappregistry): default stack name is not meaningful and causes conflict when multiple stacks deployed to the same account-region #23823

Merged
merged 9 commits into from
Feb 8, 2023

Conversation

jungle-amazon
Copy link
Contributor

@jungle-amazon jungle-amazon commented Jan 25, 2023

  • Replace stage association error with warning
  • Deprecate stackId in TargetApplication options
  • Provide a default dynamic stack name for CreateTargetApplication stack with a reference to the application name
  • Provide a default dynamic stack name for ExistingTargetApplication stack with a reference to the application ID

This fixes: 23861

Note: With this change to stackName, you may run into the following error during deployment if you have been using the default stack id and name by not explicitly setting them.

Resource handler returned message: "You already own an application 'MyApplicationName' (Service: ServiceCatalogAppRegistry, Status Code: 409, Request ID: xxxx)" (RequestToken: yyyy, HandlerErrorCode: InvalidRequest)

To address this error, explicitly set the stackName value to the name of your existing stack. For example:

const associatedApp = new ApplicationAssociator(app, 'MyApplicationAssociator', {
  applications: [ TargetApplication.createApplicationStack({
    applicationName: 'MyApplicationName',
    stackName: 'ApplicationAssociatorStack', // add your existing stack name here
    ...

All Submissions:

Adding new Construct Runtime Dependencies:

  • This PR adds new construct runtime dependencies following the process described here

New Features

  • Have you added the new feature to an integration test?
    • Did you use yarn integ to deploy the infrastructure and generate the snapshot (i.e. yarn integ without --dry-run)?

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

…t defects

- Replace stage association error with warning
- Replace the hardcoded stack ID for CreateTargetApplication with a reference to the application name
- Replace the hardcoded stack ID for ExistingTargetApplication with a reference to the application ID
@gitpod-io
Copy link

gitpod-io bot commented Jan 25, 2023

@github-actions github-actions bot added p2 beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK labels Jan 25, 2023
@aws-cdk-automation aws-cdk-automation requested a review from a team January 25, 2023 00:49
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

@aws-cdk-automation aws-cdk-automation dismissed their stale review January 25, 2023 01:22

✅ Updated pull request passes all PRLinter validations. Dissmissing previous PRLinter review.

@jungle-amazon jungle-amazon marked this pull request as ready for review January 27, 2023 01:08
rix0rrr
rix0rrr previously requested changes Feb 1, 2023
Copy link
Contributor

@rix0rrr rix0rrr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since renaming a stack is not possible, what will happen in practice is that the old Application will be deleted and a new Application will be created (or actually, since CDK doesn't automatically clean up old stacks, a new application will be created, full stop).

  • If the new application name is the same as the old application name, the creation will fail.

This means that users currently using this library, whenever they upgrade, will be stuck with an undeployable code base, that needs manual work before they can deploy again. They will need to get rid of the applicationassociator in the old code base, deploy again to unregister all stacks, then upgrade the library and then use the new application associator.

Are you willing to put your users through that? If not, you probably need some mechanism for backwards compatibility so people with existing code bases won't end up stuck.

@@ -90,7 +91,7 @@ class CreateTargetApplication extends TargetApplication {
super();
}
public bind(scope: Construct): BindTargetApplicationResult {
const stackId = this.applicationOptions.stackId ?? 'ApplicationAssociatorStack';
const stackId = this.applicationOptions.stackId ?? `CreateTargetApplication${this.applicationOptions.applicationName}`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After thinking about it a little, I think this is the wrong way to go about it. A Stack has two identifiers:

  • id, used as an ID in the construct tree (needs to be unique within the scope in the construct tree)
  • stackName, the name of the CloudFormation Stack being deployed (needs to be unique within the account+region it is deployed to, defaults to id if not supplied).

I think what is happening here is that you are trying to change stackName by changing id, is that right?

If that is the case, doesn't it make more sense to leave id where it is, and explicitly set stackName to the value you're trying to achieve?


Also, CreateXxx is not a great name for a resource (Create is a Verb, but a resource is a Noun). Maybe make it something Application-MyGreatApplication-Stack ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes you are correct, we are trying to change stackName by changing the id. Your proposed approach of setting the stackName makes more sense and I have updated the commit with this change instead.

I also updated the stackName format as per your suggestion.


For your first concern about "renaming" the stack, it is true that if the user wants to continue to rely on the default stack name and keep the same application name, the user will see a conflict because the new stack with the updated name will attempt to create an app that already exists.

I think a workaround for the user would be to specify the previous default stack name ApplicationAssociatorStack as a stackName option property to keep using the old stack name.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a workaround for the user would be to specify the previous default stack name ApplicationAssociatorStack as a stackName option property to keep using the old stack name.

👍 Sounds good.

The next question is: how will users that get affected by this know that they have to do that?

Here is my suggestion: they will probably read the change log and find this PR. Please edit the description of this PR and add a section that says "if you run into the following error (...error message here...) make sure to set stackName to the name of your stack. For example:

new ApplicationAssociator(..., {
  stackName: 'whatever-theold-<your application name here>-stackname-was'

"

Something like that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes a lot of sense, I've added this section in the PR description.

@jungle-amazon jungle-amazon changed the title fix(servicecatalogappregistry): fix L2 ApplicationAssociator construct defects fix(servicecatalogappregistry): conflicting stack names when multiple apps are deployed to same account and region Feb 2, 2023
@mergify mergify bot dismissed rix0rrr’s stale review February 2, 2023 23:15

Pull request has been modified.

@jungle-amazon jungle-amazon changed the title fix(servicecatalogappregistry): conflicting stack names when multiple apps are deployed to same account and region fix(servicecatalogappregistry): default stack name is not meaningful and causes conflict when multiple stacks deployed to the same account-region Feb 2, 2023
rix0rrr
rix0rrr previously requested changes Feb 7, 2023
@@ -117,7 +119,11 @@ class ExistingTargetApplication extends TargetApplication {
super();
}
public bind(scope: Construct): BindTargetApplicationResult {
const arnComponents = cdk.Arn.split(this.applicationOptions.applicationArnValue, cdk.ArnFormat.SLASH_RESOURCE_SLASH_RESOURCE_NAME);
const applicationId = arnComponents.resourceName;
const stackId = this.applicationOptions.stackId ?? 'ApplicationAssociatorStack';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it looks like stackId originally existed to change the stack name (but was the wrong mechanism for that), can we also deprecate stackId?

Add:

  * @deprecated Use `stackName` instead to control the name of the stack

To its docstring?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this will be more helpful to the user. I'll add a deprecated statement to the docstring in the next commit.

@@ -90,7 +91,7 @@ class CreateTargetApplication extends TargetApplication {
super();
}
public bind(scope: Construct): BindTargetApplicationResult {
const stackId = this.applicationOptions.stackId ?? 'ApplicationAssociatorStack';
const stackId = this.applicationOptions.stackId ?? `CreateTargetApplication${this.applicationOptions.applicationName}`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a workaround for the user would be to specify the previous default stack name ApplicationAssociatorStack as a stackName option property to keep using the old stack name.

👍 Sounds good.

The next question is: how will users that get affected by this know that they have to do that?

Here is my suggestion: they will probably read the change log and find this PR. Please edit the description of this PR and add a section that says "if you run into the following error (...error message here...) make sure to set stackName to the name of your stack. For example:

new ApplicationAssociator(..., {
  stackName: 'whatever-theold-<your application name here>-stackname-was'

"

Something like that.

@mergify mergify bot dismissed rix0rrr’s stale review February 7, 2023 20:55

Pull request has been modified.

@mergify
Copy link
Contributor

mergify bot commented Feb 8, 2023

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: e6fd324
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit 420b5ff into aws:main Feb 8, 2023
@mergify
Copy link
Contributor

mergify bot commented Feb 8, 2023

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

mergify bot pushed a commit that referenced this pull request Feb 16, 2023
…ack name for Application stack (#24171)

* Assign value of `stackName` to `stackId` for Application stack, so the stack id will always be the same as stack name. Users wanting to control stack id can do so via `stackName`.

Closes #24160.

Background:
* Customers wish to control or modify the stack id of the Application stack to follow their project conventions within CDK.
* In previous [fix](#23823), we had deprecated the stack id to push users towards using stack name as the main mechanism for stack identification.

Note on backward-compatibility:

After this change, the `stackId` parameter can no longer be used to control the application stack id. The stack id will always match stack name, and the default stack name if not specified will be `Application-${APPLICATION_IDENTIFIER}-Stack`. `${APPLICATION_IDENTIFIER}` is application name for CreateTargetApplication and application id for ExistingTargetApplication.

If you created an application stack prior to aws-cdk [release v2.64.0](https://github.com/aws/aws-cdk/releases/tag/v2.64.0) and did not specify a stack id or name, you may run into the following error during deployment due to the creation attempt of a new stack with the same application:
```log
Resource handler returned message: "You already own an application 'MyApplicationName' (Service: ServiceCatalogAppRegistry, Status Code: 409, Request ID: xxxx)" (RequestToken: yyyy, HandlerErrorCode: InvalidRequest)
```

To address this error, you can set the `stackName` value to match your existing stack. For example:
```typescript
const associatedApp = new ApplicationAssociator(app, 'MyApplicationAssociator', {
  applications: [ TargetApplication.createApplicationStack({
    applicationName: 'MyApplicationName',
    stackName: 'ApplicationAssociatorStack', // Add your existing stack name here
    ...
```
This will result in the existing stack deploying with the previous name, and the id in CDK will reflect this same stack name.

Related links:
* Previous PR: #23823
* Previous GitHub issue: #23861
* Original reason that introduced `stackId`: #22508

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@jungle-amazon jungle-amazon deleted the l2_fixes branch February 20, 2023 19:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK p2
Projects
None yet
3 participants