cdk: missing ca-west-1 region in aws-entities causes cdk vended custom resources to fail deployment
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::value
Reproduction 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::value
Possible 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
Findings:
- Reproducible in CDK CLI/Lib version
2.147.1 (build d3695d4). If we use the default CDK app settings withoutenvproperty while creating stack,- It creates
cdk.out/<<StackName>>.template.jsonwithMappings::LatestNodeRuntimeMapnode with missing entry forca-west-1region. - During stack deployment, it fails during changeset creation with the below error:
❌ Issue30694Stack failed: Error [ValidationError]: Template error: Unable to get mapping for LatestNodeRuntimeMap::ca-west-1::value at Request.extractError (/Users/ashdhin/dev/repros/cdk/issue30694/node_modules/aws-cdk/lib/index.js:401:46723) at Request.callListeners (/Users/ashdhin/dev/repros/cdk/issue30694/node_modules/aws-cdk/lib/index.js:401:91777) at Request.emit (/Users/ashdhin/dev/repros/cdk/issue30694/node_modules/aws-cdk/lib/index.js:401:91225) at Request.emit (/Users/ashdhin/dev/repros/cdk/issue30694/node_modules/aws-cdk/lib/index.js:401:199828) at Request.transition (/Users/ashdhin/dev/repros/cdk/issue30694/node_modules/aws-cdk/lib/index.js:401:193380) at AcceptorStateMachine.runTo (/Users/ashdhin/dev/repros/cdk/issue30694/node_modules/aws-cdk/lib/index.js:401:158252) at /Users/ashdhin/dev/repros/cdk/issue30694/node_modules/aws-cdk/lib/index.js:401:158582 at Request.<anonymous> (/Users/ashdhin/dev/repros/cdk/issue30694/node_modules/aws-cdk/lib/index.js:401:193672) at Request.<anonymous> (/Users/ashdhin/dev/repros/cdk/issue30694/node_modules/aws-cdk/lib/index.js:401:199903) at Request.callListeners (/Users/ashdhin/dev/repros/cdk/issue30694/node_modules/aws-cdk/lib/index.js:401:91945) { code: 'ValidationError', time: 2024-06-27T20:29:50.742Z, requestId: '739abc90-9dc3-4d69-8435-61e8b5bb243a', statusCode: 400, retryable: false, retryDelay: 144.327793178868 } ❌ Deployment failed: Error [ValidationError]: Template error: Unable to get mapping for LatestNodeRuntimeMap::ca-west-1::value at Request.extractError (/Users/ashdhin/dev/repros/cdk/issue30694/node_modules/aws-cdk/lib/index.js:401:46723) at Request.callListeners (/Users/ashdhin/dev/repros/cdk/issue30694/node_modules/aws-cdk/lib/index.js:401:91777) at Request.emit (/Users/ashdhin/dev/repros/cdk/issue30694/node_modules/aws-cdk/lib/index.js:401:91225) at Request.emit (/Users/ashdhin/dev/repros/cdk/issue30694/node_modules/aws-cdk/lib/index.js:401:199828) at Request.transition (/Users/ashdhin/dev/repros/cdk/issue30694/node_modules/aws-cdk/lib/index.js:401:193380) at AcceptorStateMachine.runTo (/Users/ashdhin/dev/repros/cdk/issue30694/node_modules/aws-cdk/lib/index.js:401:158252) at /Users/ashdhin/dev/repros/cdk/issue30694/node_modules/aws-cdk/lib/index.js:401:158582 at Request.<anonymous> (/Users/ashdhin/dev/repros/cdk/issue30694/node_modules/aws-cdk/lib/index.js:401:193672) at Request.<anonymous> (/Users/ashdhin/dev/repros/cdk/issue30694/node_modules/aws-cdk/lib/index.js:401:199903) at Request.callListeners (/Users/ashdhin/dev/repros/cdk/issue30694/node_modules/aws-cdk/lib/index.js:401:91945) { code: 'ValidationError', time: 2024-06-27T20:29:50.742Z, requestId: '739abc90-9dc3-4d69-8435-61e8b5bb243a', statusCode: 400, retryable: false, retryDelay: 144.327793178868 } Template error: Unable to get mapping for LatestNodeRuntimeMap::ca-west-1::value - It creates
- If we explicitly specify
envproperty during CDK stack creation in CDK app, it does not createMappings::LatestNodeRuntimeMapnode incdk.out/<<StackName>>.template.jsonand deployment succeeds.
The region has been added but I'm leaving this issue open because the problem of needing to manually add regions for our custom resources to work is not yet resolved.
Hi @TheRealAmazonKendra, do you know if the change with the region was already released? If no, do you know more or less when we could expect it? (<- I'm referring only to the region, not the larger effort)
For now we are pinning v2.145.0 to prevent our pipelines from stopping to work.
Thanks!
Hi @dreamorosi the fix was merged 3 days ago so it will be released in the next version.
Hey @dreamorosi, are you still running into this issue on the latest release? I am seeing ca-west-1 in the mapping.
Hi @scanlonp - I can confirm that the issue is no longer present in version 2.149.0.
Thank you all!
Comments on closed issues and PRs are hard for our team to see. If you need help, please open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.
Comments on closed issues and PRs are hard for our team to see. If you need help, please open a new issue that references this one.