aws-lambda: inconsistent behavior in fromLayerVersionArn during deploys
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
### Describe the bug
when modifying an existing fromLayerVersionArn value with a arn that is already attached the deploy nor synth fails
### Expected Behavior
Throw an error as follows
Two different versions of the same layer are not allowed to be referenced in the same function.
### Current Behavior
deploys successfully but does not change anything on the service
### Reproduction Steps
1. Create CDK app with function
2. Attach layer using
```
const layer1 = lambda.LayerVersion.fromLayerVersionArn(
this,
"layerpy",
"arn:aws:lambda:us-east-1::layer:mylayer1:1"
);
const layer2 = lambda.LayerVersion.fromLayerVersionArn(
this,
"layerpy1",
"arn:aws:lambda:us-east-1::layer:mylayer2:1"
);
```
3. deploy
4. modify layer2 with same layer as 1
5. deploy and observe no errors
### Possible Solution
_No response_
### Additional Information/Context
Side note: observed after deploying two fromLayerVersionArn with same layer then if we add another fromLayerVersionArn with same layer, the cfn will fail with `Two different versions of the same layer are not allowed to be referenced in the same function.` which is great but the next deploy/cfn template is in a failed state rather than a rollback complete state
### CDK CLI Version
2.150.0
### Framework Version
_No response_
### Node.js Version
v20.11.1
### OS
MacOS
### Language
TypeScript
### Language Version
5.5.3
### Other information
_No response_
Contributor guide
Research direction
Start with the lambda.LayerVersion.fromLayerVersionArn entry point and reproduce the deployment sequence described in the issue, including changing layer2 to layer1. The fix is done when synth or deploy reports that two versions of the same layer cannot be referenced and the deployment does not leave the CloudFormation stack in a failed state.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, typescript
- Domain
- cloud, infrastructure
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100