-
Notifications
You must be signed in to change notification settings - Fork 4.5k
cdk: missing ca-west-1 region in aws-entities causes cdk vended custom resources to fail deployment #30694
Description
Describe the bug
From 2.146.0 onwards, cdk vended custom resources are now region aware - this change seems to have been introduced in #30108.
To my understanding this means that when deploying a cdk vended custom resource, the LATEST_NODE_RUNTIME_MAP is used to lookup the Node.js version to use in the underlying Lambda function.
This in turn appears to look up the regions in the AWS_REGIONS_AND_RULES map in the packages/aws-cdk-lib/region-info/lib/aws-entities.ts file - which is missing an AWS region (ca-west-1).
Expected Behavior
I should be able to deploy a CDK stack that uses cdk-vended custom resources in this region.
Current Behavior
When deploying in ca-west-1, the stack fails due to the missing region in the Mapping node of the generated CloudFormation stack:
❌ Deployment failed: Error [ValidationError]: Template error: Unable to get mapping for LatestNodeRuntimeMap::ca-west-1::valueReproduction Steps
- Initialize a new CDK app with
npx aws-cdk@latest init app --language typescript - Open
lib/test-stack.ts - Paste code below
import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { Code, Function as LambdaFunction, Runtime } from 'aws-cdk-lib/aws-lambda';
export class TestRegionIssueStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
new LambdaFunction(this, 'TestFunction', {
runtime: Runtime.NODEJS_20_X,
handler: 'index.handler',
code: Code.fromInline('exports.handler = async () => "Hello, world!";'),
logRetention: 7, // this adds a cdk vended custom resource
});
}
}This will generate a cdk vended custom resource because of the logRetention prop.
- Run
npm run cdk synthto generate the CloudFormation stack file - Open the
cdk.out/TestStack.template.jsonand find theMappings.LatestNodeRuntimeMap - Observe that the
ca-west-1region is missing from the mapping - Set region to
ca-west-1viaexport AWS_REGION=ca-west-1 - Observe error during CloudFormation changeset creation
❌ TestStack failed: Error [ValidationError]: Template error: Unable to get mapping for LatestNodeRuntimeMap::ca-west-1::valuePossible Solution
No response
Additional Information/Context
My team Powertools for AWS Lambda deploys Lambda layers in all regions, including the missing one.
We discovered the issue in our canaries which were now failing to deploy in ca-west-1. Downgrading to 2.145.0 fixed the issue.
CDK CLI Version
2.146.0
Framework Version
No response
Node.js Version
20.x
OS
Linux, Mac
Language
TypeScript
Language Version
No response
Other information
No response