Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

cdk: missing ca-west-1 region in aws-entities causes cdk vended custom resources to fail deployment #30694

Closed
dreamorosi opened this issue Jun 27, 2024 · 8 comments
Labels
@aws-cdk/aws-lambda Related to AWS Lambda bug This issue is a bug. effort/medium Medium work item – several days of effort p1

Comments

@dreamorosi
Copy link
Contributor

dreamorosi commented Jun 27, 2024

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

  1. Initialize a new CDK app with npx aws-cdk@latest init app --language typescript
  2. Open lib/test-stack.ts
  3. 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.

  1. Run npm run cdk synth to generate the CloudFormation stack file
  2. Open the cdk.out/TestStack.template.json and find the Mappings.LatestNodeRuntimeMap
  3. Observe that the ca-west-1 region is missing from the mapping
  4. Set region to ca-west-1 via export AWS_REGION=ca-west-1
  5. 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

@dreamorosi dreamorosi added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jun 27, 2024
@github-actions github-actions bot added the @aws-cdk/aws-lambda Related to AWS Lambda label Jun 27, 2024
@ashishdhingra ashishdhingra self-assigned this Jun 27, 2024
@ashishdhingra ashishdhingra added needs-reproduction This issue needs reproduction. and removed needs-triage This issue or PR still needs to be triaged. labels Jun 27, 2024
@ashishdhingra
Copy link
Contributor

ashishdhingra commented Jun 27, 2024

Findings:

  • Reproducible in CDK CLI/Lib version 2.147.1 (build d3695d4). If we use the default CDK app settings without env property while creating stack,
    • It creates cdk.out/<<StackName>>.template.json with Mappings::LatestNodeRuntimeMap node with missing entry for ca-west-1 region.
    • 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
    
  • If we explicitly specify env property during CDK stack creation in CDK app, it does not create Mappings::LatestNodeRuntimeMap node in cdk.out/<<StackName>>.template.json and deployment succeeds.

@ashishdhingra ashishdhingra added p2 effort/medium Medium work item – several days of effort effort/small Small work item – less than a day of effort and removed needs-reproduction This issue needs reproduction. effort/medium Medium work item – several days of effort labels Jun 27, 2024
@ashishdhingra ashishdhingra removed their assignment Jun 27, 2024
@TheRealAmazonKendra TheRealAmazonKendra added p1 and removed p2 labels Jul 3, 2024
@TheRealAmazonKendra
Copy link
Contributor

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.

@TheRealAmazonKendra TheRealAmazonKendra added effort/medium Medium work item – several days of effort and removed effort/small Small work item – less than a day of effort labels Jul 11, 2024
@dreamorosi
Copy link
Contributor Author

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!

@xazhao
Copy link
Contributor

xazhao commented Jul 15, 2024

Hi @dreamorosi the fix was merged 3 days ago so it will be released in the next version.

@scanlonp
Copy link
Contributor

Hey @dreamorosi, are you still running into this issue on the latest release? I am seeing ca-west-1 in the mapping.

@dreamorosi
Copy link
Contributor Author

Hi @scanlonp - I can confirm that the issue is no longer present in version 2.149.0.

Thank you all!

Copy link

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.

@aws-cdk-automation
Copy link
Collaborator

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.

@aws aws locked as resolved and limited conversation to collaborators Jul 25, 2024
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
@aws-cdk/aws-lambda Related to AWS Lambda bug This issue is a bug. effort/medium Medium work item – several days of effort p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants