- 
                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.ALLcontains 43+ runtime entries (including deprecated ones), but AWS Lambda limitscompatibleRuntimesto maximum 15 entries and only accepts currently supported runtimes. When users specifycompatibleRuntimes: Runtime.ALLfor Lambda layers, deployment fails with CloudFormation validation errors:This breaks existing user code that relies on the documented
Runtime.ALLconstant for Lambda layers.Description of changes
Modified the LayerVersion constructor to detect when
compatibleRuntimesis set toRuntime.ALLand treat it asundefined, allowing AWS to use its default "all supported runtimes" behavior:CfnLayerVersionresource creation to check forRuntime.ALLvia reference equalityRuntime.ALLis detected,compatibleRuntimesis set toundefinedin the CloudFormation templateundefined, AWS Lambda defaults to supporting all currently supported runtimes (the intended behavior)undefinedwork as beforeRuntime.ALLis equivalent toundefinedTechnical 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.eachto verify that bothRuntime.ALLandundefinedresult in omittingCompatibleRuntimesfrom the CloudFormation template. This eliminates code duplication and follows Jest best practices. All existing layer tests continue to pass (7/7).CompatibleRuntimesis 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.ALLproducesundefinedin CloudFormation templateundefinedcompatibleRuntimes producesundefinedin CloudFormation templatetest.eachto eliminate duplicationChecklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license