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

(aws-tools): CLI --hotswap -> We don't support attributes of the 'AWS::CloudFormation::Stack' resource #23533

Open
2 tasks
twixr opened this issue Jan 2, 2023 · 10 comments
Labels
feature-request A feature should be added or improved. p1 package/tools Related to AWS CDK Tools or CLI

Comments

@twixr
Copy link

twixr commented Jan 2, 2023

Describe the feature

Could not perform a hotswap deployment, because the CloudFormation template could not be resolved: We don't support attributes of the 'AWS::CloudFormation::Stack' resource. This is a CDK limitation.

Use Case

I work with Nested stacks and I have Lambda in nested stacks.
When I do a code change to a Lambda, I would really like to have hotswap working. This works for the main stack, but for a Lambda code change located in a Nested stack, this doesn't work.

Output of cdk diff:

image

As you can see, the Lambda code change in a nested stack triggers a change of type AWS::CloudFormation::Stack which is not supported.

Proposed Solution

No response

Other Information

Some other similar issues:
#19421
#19644

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

CDK version used

2.58.1 (build 3d8df57)

Environment details (OS name and version, etc.)

Ubuntu 20.04 LTS (Windows WSL2)

@twixr twixr added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Jan 2, 2023
@github-actions github-actions bot added the package/tools Related to AWS CDK Tools or CLI label Jan 2, 2023
@twixr
Copy link
Author

twixr commented Jan 2, 2023

Any workaround for this is also welcome, since currently even the smallest change takes 4 minutes.
I even completely removed the use of layers, since they also trigger a full deployment.
I can't not use the nested stacks since my application uses more than 500 resources

@peterwoodworth
Copy link
Contributor

We should already support the hotswap of resources found in nested stacks #18950

Could you provide the stack code you're using to define this nested stack? Thanks

@peterwoodworth peterwoodworth added bug This issue is a bug. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Jan 4, 2023
@peterwoodworth peterwoodworth added p1 needs-reproduction This issue needs reproduction. labels Jan 4, 2023
@twixr
Copy link
Author

twixr commented Jan 4, 2023

Seems you are right. Have tried it with a minimal reproduction Stack and it seems to work great.
Around 6-7 seconds to hotswap a Lambda in a nested stack.

Will investigate further with my whole setup and check why it doesn't work in our setup.

The diff provided by CDK is nearly the same. Feels kinda strange that the diff is the same (except for the generated file ids) but still it refuses in my other case a hotswap.

Edit: Strangely it seems to work now. Not sure what changed.
I guess that's just being a software engineer 🤓

@twixr twixr closed this as completed Jan 4, 2023
@github-actions
Copy link

github-actions bot commented Jan 4, 2023

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

@peterwoodworth
Copy link
Contributor

glad to hear it worked out @twixr! Please feel free to report again if you run into this issue again

@twixr
Copy link
Author

twixr commented Jan 28, 2023

Hi @peterwoodworth I got the issue again and spend quite some hours debugging my whole stack (which is quite large with 10 nested stacks or so)

I did manage to find the reason why the hotswap wasn't working in my case, and also managed to create a minimal reproduction setup for this.
My setup is:

  • A root stack containing nothing but two nested stacks (NestedStackA and NestedStackB)
  • In NestedStackA I create a SNS topic
  • In NestedStackB I create a Lambda with the SNS Topic ARN as environment variable

I do this by passing the topicArn property from the SNS topic in NestedStackA as parameter and use that parameter (just a string) to pass to the environment object for the Lambda.
Note: I'm using aws_lambda_nodejs.NodejsFunction to create my Lambda.

If I put in the topicArn hardcoded, then hotswap works. But somehow if I use it as reference from NestedStackA then it is not able to do a hotswap.

My Stack code:

export class RootStack extends Stack {
  constructor(scope: Construct, id: string, stackProps: StackProps) {
    super(scope, id, stackProps);

    const stack = new NestedStackA(this, `NestedStackA`, stackProps);
    new NestedStackB(this, `NestedStackB`, stackProps, stack.snsTopic.topicArn);
  }
}

class NestedStackA extends NestedStack {
  snsTopic: aws_sns.Topic;
  constructor(scope: Construct, id: string, stackProps: StackProps) {
    super(scope, id, stackProps);

    this.snsTopic = new aws_sns.Topic(this, 'SNSTopic');
  }
}

class NestedStackB extends NestedStack {
  constructor(scope: Construct, id: string, stackProps: StackProps, snsTopicArn: string) {
    super(scope, id, stackProps);

    new aws_lambda_nodejs.NodejsFunction(this, 'TestLambda', {
      entry: 'test-lambda.ts',
      runtime: aws_lambda.Runtime.NODEJS_16_X,
      environment: {
        SNS: snsTopicArn
      }
    });
  }
}

After some extra testing I found out that it has nothing to do with SNS in general, just that we were using that.
But anything that references to another nested stack will cause hotswap to fail.
Not sure if it is only in Lambda environment, or just in general if you reference something from another nested stack that it doesn't work.

Hopefully this is useful information.

I think for now I can workaround this issue by putting those resources I need in other nested stacks in the root stack rather than in a nested stack. That should hopefully mitigate this issue.

@twixr twixr reopened this Jan 28, 2023
@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Jan 29, 2023
@fab-mindflow
Copy link

fab-mindflow commented Mar 4, 2023

We also have a large stack with lot nested stacks, each one having multiple lambdas. Those stacks have reference to SSM parameters and the deploy is super long (> 4 minutes) for 2 reasons:

  1. could not perform hotswap
Could not perform a hotswap deployment, because the CloudFormation template could not be resolved: Parameter or resource 'AReferenceToSomeParameterInSSMCreatedByAnotherStack' could not be found for evaluation
  1. assets:

This is caused by #18045 and #20716

@louislatreille
Copy link

louislatreille commented Aug 11, 2023

I'm getting a very similar error.

Could not perform a hotswap deployment, because the CloudFormation template could not be resolved: We don't support attributes of the 'AWS::Cognito::UserPool' resource. This is a CDK limitation.

I have a parent stack that creates a bunch of resources, including a Cognito UserPool, and a nested stack that mostly contains Lambda Functions. I'm passing down some of the parent resource references to the nested stack and use them in the Lambda Functions. This includes the UserPool.

NPM modules:

"@aws-cdk/aws-apigatewayv2-alpha": "2.65.0-alpha.0",
"@aws-cdk/aws-cognito-identitypool-alpha": "2.65.0-alpha.0",
"@aws-cdk/aws-redshift-alpha": "2.65.0-alpha.0",
"@aws-cdk/aws-synthetics-alpha": "2.65.0-alpha.0",
"cdk-monitoring-constructs": "3.0.3",
"aws-cdk": "2.65.0",
"aws-cdk-lib": "2.65.0",
"cdk": "2.65.0",
"cdk-constants": "3.0.3",
"constructs": "10.1.200",
"esbuild": "0.16.10"

@astrocreep
Copy link

Same issues here. One root stack with four nested stacks. Three of them set up DynamoDB, Kinesis Streams and so on. The last one contains Lambda functions that use some references. Result is:

Could not perform a hotswap deployment, because the CloudFormation template could not be resolved: We don't support attributes of the 'AWS::CloudFormation::Stack' resource. This is a CDK limitation.

mergify bot pushed a commit that referenced this issue Sep 28, 2023
…7195)

This PR solves two problems when doing hotswap deployments with nested stacks.

1. Adding capabilities to evaluate CFN parameters of `AWS::CloudFormation::Stack` type (i.e. a nested stack). In this PR, we are only resolving `Outputs` section of `AWS::CloudFormation::Stack` and it can be expanded to other fields in the future. See https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/quickref-cloudformation.html#w2ab1c17c23c19b5 for CFN documentation around using Outputs ref parameters
2. If a template has parameters with default values and they are not provided (a value) by the parent stack when invoking, then resolve these parameters using the default values in the template.

Partially helps #23533 and #25418

----

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

naedx commented Jul 15, 2024

I'm also having the same issue.

The details are here: #30841 (comment)

@pahud pahud added feature-request A feature should be added or improved. and removed bug This issue is a bug. labels Aug 12, 2024
@pahud pahud removed the needs-reproduction This issue needs reproduction. label Aug 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request A feature should be added or improved. p1 package/tools Related to AWS CDK Tools or CLI
Projects
None yet
Development

No branches or pull requests

8 participants