-
Notifications
You must be signed in to change notification settings - Fork 4.3k
chore(lambda): handle Runtime.ALL correctly in LayerVersion compatibleRuntimes #35351
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@pahud |
}); | ||
}); | ||
|
||
test('Runtime.ALL is handled correctly by omitting compatibleRuntimes', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 2 tests that we are adding are a duplication of code, since they are identical but with just changing the compatibleRuntimes
value. I'd suggest we better do something like this to avoid the duplication of code:
test.each([
['Runtime.ALL is handled correctly', { compatibleRuntimes: lambda.Runtime.ALL }],
['undefined compatibleRuntimes is handled correctly', {}]
])('%s by omitting compatibleRuntimes', (_, props) => {
// GIVEN
const stack = new cdk.Stack();
const bucket = new s3.Bucket(stack, 'Bucket');
const code = new lambda.S3Code(bucket, 'ObjectKey');
// WHEN
new lambda.LayerVersion(stack, 'LayerVersion', {
code,
...props
});
// the remaining stays the same
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All addressed. Thank you
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
Comments on closed issues and PRs are hard for our team to see. |
Issue # (if applicable)
Closes #35348.
Reason for this change
Runtime.ALL
contains 43+ runtime entries (including deprecated ones), but AWS Lambda limitscompatibleRuntimes
to maximum 15 entries and only accepts currently supported runtimes. When users specifycompatibleRuntimes: Runtime.ALL
for Lambda layers, deployment fails with CloudFormation validation errors:This breaks existing user code that relies on the documented
Runtime.ALL
constant for Lambda layers.Description of changes
Modified the LayerVersion constructor to detect when
compatibleRuntimes
is set toRuntime.ALL
and treat it asundefined
, allowing AWS to use its default "all supported runtimes" behavior:CfnLayerVersion
resource creation to check forRuntime.ALL
via reference equalityRuntime.ALL
is detected,compatibleRuntimes
is set toundefined
in the CloudFormation templateundefined
, AWS Lambda defaults to supporting all currently supported runtimes (the intended behavior)undefined
work as beforeRuntime.ALL
is equivalent toundefined
Technical Implementation:
Describe any new or updated permissions being added
N/A - No IAM permissions or resource access changes.
Description of how you validated changes
test.each
to verify that bothRuntime.ALL
andundefined
result in omittingCompatibleRuntimes
from the CloudFormation template. This eliminates code duplication and follows Jest best practices. All existing layer tests continue to pass (7/7).CompatibleRuntimes
is omitted from the CloudFormation template. The AWS service automatically applies compatibility with all currently supported runtimes, which is the intended behavior forRuntime.ALL
.Test Coverage:
Runtime.ALL
producesundefined
in CloudFormation templateundefined
compatibleRuntimes producesundefined
in CloudFormation templatetest.each
to eliminate duplicationChecklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license