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
chore(lambda): handle Runtime.ALL correctly in LayerVersion compatibleRuntimes (#35351)
### Issue # (if applicable)
Closes#35348.
### Reason for this change
`Runtime.ALL` contains 43+ runtime entries (including deprecated ones), but AWS Lambda limits `compatibleRuntimes` to maximum 15 entries and only accepts currently supported runtimes. When users specify `compatibleRuntimes: Runtime.ALL` for Lambda layers, deployment fails with CloudFormation validation errors:
- "Member must have length less than or equal to 15"
- "Member must satisfy enum value set" for supported runtimes only
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 to `Runtime.ALL` and treat it as `undefined`, allowing AWS to use its default "all supported runtimes" behavior:
- Added conditional logic in `CfnLayerVersion` resource creation to check for `Runtime.ALL` via reference equality
- When `Runtime.ALL` is detected, `compatibleRuntimes` is set to `undefined` in the CloudFormation template
- When `undefined`, AWS Lambda defaults to supporting all currently supported runtimes (the intended behavior)
- All other behavior remains unchanged - specific runtime arrays and `undefined` work as before
- Updated documentation to clarify that `Runtime.ALL` is equivalent to `undefined`
**Technical Implementation**:
```typescript
compatibleRuntimes: (props.compatibleRuntimes === Runtime.ALL)
? undefined
: props.compatibleRuntimes?.map(r => r.name),
```
### Describe any new or updated permissions being added
N/A - No IAM permissions or resource access changes.
### Description of how you validated changes
- **Unit tests**: Added comprehensive test cases using `test.each` to verify that both `Runtime.ALL` and `undefined` result in omitting `CompatibleRuntimes` from the CloudFormation template. This eliminates code duplication and follows Jest best practices. All existing layer tests continue to pass (7/7).
- **Integration tests**: No additional integration tests required as this change leverages existing AWS Lambda service behavior when `CompatibleRuntimes` is omitted from the CloudFormation template. The AWS service automatically applies compatibility with all currently supported runtimes, which is the intended behavior for `Runtime.ALL`.
**Test Coverage**:
- ✅ `Runtime.ALL` produces `undefined` in CloudFormation template
- ✅ `undefined` compatibleRuntimes produces `undefined` in CloudFormation template
- ✅ Specific runtime arrays work unchanged
- ✅ Empty runtime array validation still throws error
- ✅ All existing layer functionality preserved
- ✅ Refactored tests using `test.each` to eliminate duplication
### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)
----
*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
0 commit comments