You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Lambda extracts the layers in the order (low to high) listed by the function. Lambda merges folders with the same name, so if the same file appears in multiple layers, the function uses the version in the last extracted layer.
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:recognizeLayerVersion is 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.
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.
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.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
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:recognizeLayerVersion
is 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