aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.65k stars 3.91k forks source link

(cloudformation-include): Lambda stack deployment creates a new Lambda even though preservelogicalIds is true #19415

Closed Nehaparakh95 closed 4 months ago

Nehaparakh95 commented 2 years ago

What is the problem?

While deploying a stack consisting of lambdas and Even source Mapping as well as Lambda aliases, these lambdas are getting replaced after running the cdk diff command and shows that new lambdas will be created. The same does not happen for a stack consisting of S3s, DDBs etc. On deploying, it shows that the UPDATE is COMPLETE. Moreover, the diff does not show addition of any CDKMetadata but on deployment the metadata is in fact added to the stack.

Reproduction Steps

Create a CFN stack consisting of lambdas, even source mapping and aliased and try converting it into CDKStack using CfnInclude

What did you expect to happen?

The diff should not show some resources are replaced and CDKMetadata should show up as one of the resources when running the diff command and all the logical Ids of the resources should be preserved

What actually happened?

Diff did not have CDKMetadata LogicalIds got replaced

CDK CLI Version

1.145.0 (build 9f96380)

Framework Version

No response

Node.js Version

NodeJS = 12.x;

OS

macOS Cataline 10.15.7 (19H1715)

Language

Typescript

Language Version

No response

Other information

No response

skinny85 commented 2 years ago

Hi @Nehaparakh95,

thanks for opening the issue. Can you please show your CDK code, and your template that you're including in your app?

Thanks, Adam

skinny85 commented 2 years ago

And also the output of the cdk diff command that you see 🙂.

caroline171 commented 1 year ago

Any updates on this ? I am facing the same issue when i am tracing this documentation https://aws.amazon.com/blogs/developer/migrating-cloudformation-templates-to-the-aws-cloud-development-kit/

CDK Diff

Stack MigrationStack
Parameters
[+] Parameter BootstrapVersion BootstrapVersion: {"Type":"AWS::SSM::Parameter::Value<String>","Default":"/cdk-bootstrap/hnb659fds/version","Description":"Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"}

Conditions
[+] Condition CDKMetadata/Condition CDKMetadataAvailable: {"Fn::Or":[{"Fn::Or":[{"Fn::Equals":[{"Ref":"AWS::Region"},"af-south-1"]},{"Fn::Equals":[{"Ref":"AWS::Region"},"ap-east-1"]},{"Fn::Equals":[{"Ref":"AWS::Region"},"ap-northeast-1"]},{"Fn::Equals":[{"Ref":"AWS::Region"},"ap-northeast-2"]},{"Fn::Equals":[{"Ref":"AWS::Region"},"ap-south-1"]},{"Fn::Equals":[{"Ref":"AWS::Region"},"ap-southeast-1"]},{"Fn::Equals":[{"Ref":"AWS::Region"},"ap-southeast-2"]},{"Fn::Equals":[{"Ref":"AWS::Region"},"ca-central-1"]},{"Fn::Equals":[{"Ref":"AWS::Region"},"cn-north-1"]},{"Fn::Equals":[{"Ref":"AWS::Region"},"cn-northwest-1"]}]},{"Fn::Or":[{"Fn::Equals":[{"Ref":"AWS::Region"},"eu-central-1"]},{"Fn::Equals":[{"Ref":"AWS::Region"},"eu-north-1"]},{"Fn::Equals":[{"Ref":"AWS::Region"},"eu-south-1"]},{"Fn::Equals":[{"Ref":"AWS::Region"},"eu-west-1"]},{"Fn::Equals":[{"Ref":"AWS::Region"},"eu-west-2"]},{"Fn::Equals":[{"Ref":"AWS::Region"},"eu-west-3"]},{"Fn::Equals":[{"Ref":"AWS::Region"},"me-south-1"]},{"Fn::Equals":[{"Ref":"AWS::Region"},"sa-east-1"]},{"Fn::Equals":[{"Ref":"AWS::Region"},"us-east-1"]},{"Fn::Equals":[{"Ref":"AWS::Region"},"us-east-2"]}]},{"Fn::Or":[{"Fn::Equals":[{"Ref":"AWS::Region"},"us-west-1"]},{"Fn::Equals":[{"Ref":"AWS::Region"},"us-west-2"]}]}]}

Resources
[+] AWS::S3::Bucket Template/MyBucket MyBucket 

It is showing that there are resources to add though there are not

skinny85 commented 1 year ago

Hey @caroline171,

the BootstrapVersion Parameter and CDKMetadata condition are nothing surprising - these are just additions that CDK puts into your Stack that wouldn't be there without CloudFormation. There's nothing to worry about there, you can safely cdk deploy with those changes, and none of your other resources will be affected.

I don't know what MyBucket is, but the name seems to suggest this is something you added to the CDK code yourself maybe? 🙂

In summary, the include module is working correctly, and you can safely proceed with the migration.

khushail commented 4 months ago

@Nehaparakh95 , do you still face the issue ? if yes, pls share the repro code and cdk diff to triage it again.

github-actions[bot] commented 4 months ago

This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.