Replies: 1 comment 1 reply
-
|
Is there an update on this? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Lambda layers are supposed to be extracted (and merged) in the order they're registered. This is the expected and current behaviour exhibited by AWS CDK (and CloudFormation), by default.
However, when
@aws-cdk/aws-lambda:recognizeLayerVersionis enabled, the layers are sorted at synthesis. Potentially, this reorders layers and causes breaking changes to Lambda functions which rely upon the documented extract-and-merge behaviour.aws-cdk/packages/@aws-cdk/aws-lambda/lib/function.ts
Lines 1058 to 1060 in f19ecef
According to a test included with this change in #20150 (f19ecef), a reason for sorting layers is to ensure the same hash is calculated for Lambda functions which register the same layers in a different order, but are otherwise identical.
aws-cdk/packages/@aws-cdk/aws-lambda/test/function-hash.test.ts
Lines 210 to 230 in f19ecef
But because layers can overwrite each other, the order in which they're extracted is crucial and Lambda functions which register the same layers in a different order should always have a different hash.
Regardless of the previous point, why is it necessary to mutate the layers array to calculate the Lambda function hash? A sorted copy can be used to calculate the same hash. This would cause the layers to maintain the original ordering and be extracted in the expected order.
In summary, Lambda layers can overwrite each other when extracted, so the order in which they're extracted is crucial. Lambda functions which list the same layers in a different order aren't necessarily identical and shouldn't have the same hash. Per the documentation, layers should be extracted in the order listed by the function. Extracting Lambda layers in any other order is unexpected and is a potentially breaking change.
Beta Was this translation helpful? Give feedback.
All reactions