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.72k stars 3.94k forks source link

aws_lambda: default layer name reused across stacks #18563

Closed rittneje closed 1 year ago

rittneje commented 2 years ago

What is the problem?

If two different stacks both create a LayerVersion with the same logical id and no explicit name, they will both use the exact same Layer name, which is extremely confusing and unexpected.

Reproduction Steps

Deploy two stacks into the same region. In each, create an aws_lambda.LayerVersion with the same logical id, and do not explicitly specify a layer_version_name.

What did you expect to happen?

The layer names should be distinct, and derived from the stack name, as is the case for every other resource name CDK automatically calculates.

What actually happened?

They made different versions of the same layer.

CDK CLI Version

1.130.0 (build 9c094ae)

Framework Version

No response

Node.js Version

16.13.0

OS

Alpine 3.14

Language

Python

Language Version

3.9.7

Other information

No response

BDeus commented 2 years ago

Still issue with CDK v2 i have some trouble with iam permissions as lambda layer name do not derivated from stack name. It hapen to me with BucketDeployment that use lambda layer inside

madeline-k commented 1 year ago

This is a duplicate of https://github.com/aws/aws-cdk/issues/8742, see additional info there.

This behavior is unfortunate, but I don't think CDK should add some custom behavior for Lambda Layers to paper over the issue. According to the Cloudformation documentation Logical IDs only need to be unique within a stack. So, using the same logical id in two different stacks should result in creating two resources (not both stacks updated the same resource).

github-actions[bot] commented 1 year ago

⚠️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.

rittneje commented 1 year ago

@madeline-k This cannot be easily fixed at the CloudFormation level as it would be a breaking change. CDK is in a much better position as it can gate it behind a feature flag. This would not be the first time CDK has had to work around CloudFormation's idiosyncrasies. Please reopen this issue.

madeline-k commented 1 year ago

@rittneje I've opened a ticket internally with CloudFormation. If they are not able to address this, then I will re-open this issue and we can implement it in CDK with a feature flag.

(Internal ref: P80341878)