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

aws-lambda: inconsistent behavior in fromLayerVersionArn during deploys #31006

Open ykethan opened 3 months ago

ykethan commented 3 months ago

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:<acc>:layer:mylayer1:1"
    );

    const layer2 = lambda.LayerVersion.fromLayerVersionArn(
      this,
      "layerpy1",
      "arn:aws:lambda:us-east-1:<acc>:layer:mylayer2:1"
    );
  1. deploy
  2. modify layer2 with same layer as 1
  3. 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

khushail commented 3 months ago

@ykethan , thanks for reporting this issue.

I was able to repro this, Sharing snapshots of the repro and analysis -

  1. when both layer versions are different, the deployment succeeds which is expected -
Screenshot 2024-08-02 at 4 34 21 PM
  1. Changing the layer version to same in both layers, appears in cdk diff output as below -
Screenshot 2024-08-02 at 4 35 33 PM
  1. despite cdk diff, the deployment does not make any change and succeeds here too.
Screenshot 2024-08-02 at 4 37 54 PM
ykethan commented 2 months ago

Hey @khushail, thanks for looking into this. just a additive to the reproduction, try adding a 3rd layer referencing the same layer which will cause a rollback failure. While this is on CFN that causes this but wanted to mention this behavior, as you will not be able to rollback from the failed state.