aws / aws/aws-cdk

aws-cdk-lib: CustomResource onEvent lambda function uses runtime nodejs22.x which is not latest

Open
#36,269 1 comment 1 reaction 0 assignees View on GitHub
@aws-cdk/custom-resources bug effort/medium feature-request p2
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 3h
Merged PRs (30d)
83

Description

### Describe the bug

We use cdk-nag to check our code. With latest version of aws-cdk-lib, this is failing with error

```
AwsSolutions-L1: The non-container Lambda function is not configured to use the latest runtime version. Use the latest available runtime for the targeted language to avoid technical debt. Runtimes specific to a language or framework version are deprecated when the version reaches end of life. This rule only applies to non-container Lambda functions.
```

where we have a custom resource, as the lambda function created for onEvent uses runtime nodejs22.x, and not the latest node version.

### Regression Issue

- [ ] Select this option if this issue appears to be a regression.

### Last Known Working CDK Library Version

2.221.1

### Expected Behavior

runtime of onevent lambda should use latest node version

### Current Behavior

runtime of onevent lamba use nodejs22.x

### Reproduction Steps

This code can be used to reproduce it

```
import {App, Stack, StackProps} from "aws-cdk-lib"
import {Duration, CustomResource} from "aws-cdk-lib"
import {Function, Runtime, Code} from "aws-cdk-lib/aws-lambda"
import {Provider} from "aws-cdk-lib/custom-resources"

export class ErrorStack extends Stack {
public constructor(scope: App, id: string, props: StackProps) {
super(scope, id, props)
// create the delay Lambda function with inline Python code
const myFunction = new Function(this, "MyFunction", {
runtime: Runtime.PYTHON_3_12,
handler: "index.handler",
timeout: Duration.minutes(15),
description: "foo",
code: Code.fromInline(`
import cfnresponse

def handler(event, context):
cfnresponse.send(event, context, cfnresponse.SUCCESS, response, f"Waiter-{id}")
`)
})

// create the custom resource provider
const provider = new Provider(this, "myProvider", {
onEventHandler: myFunction
})

// create the custom resource that triggers the delay
new CustomResource(this, "MyCustomResource", {
serviceToken: provider.serviceToken
})

}
}
```

When you run cdk-synth and look at the cloudformation template, notice the runtime for the onEvent lambda is nodejs22.x

```
...
"myProviderframeworkonEventAB595BBA": {
"Type": "AWS::Lambda::Function",
"Properties": {
"Code": {
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-eu-west-2"
},
"S3Key": "bdc104ed9cab1b5b6421713c8155f0b753380595356f710400609664d3635eca.zip"
},
"Description": "AWS CDK resource provider framework - onEvent (ErrorStack/myProvider)",
"Environment": {
"Variables": {
"USER_ON_EVENT_FUNCTION_ARN": {
"Fn::GetAtt": [
"MyFunction3BAA72D1",
"Arn"
]
}
}
},
"Handler": "framework.onEvent",
"LoggingConfig": {
"ApplicationLogLevel": "FATAL",
"LogFormat": "JSON"
},
"Role": {
"Fn::GetAtt": [
"myProviderframeworkonEventServiceRole94BD41C2",
"Arn"
]
},
"Runtime": "nodejs22.x",
"Timeout": 900
},
...
```

### Possible Solution

_No response_

### Additional Information/Context

_No response_

### AWS CDK Library version (aws-cdk-lib)

2.230.0

### AWS CDK CLI version

2.1033.0

### Node.js Version

24.11.1

### OS

linux

### Language

TypeScript

### Language Version

Typescript 5.9.3

### Other information

_No response_

Contributor guide

Open the contributing guide

Research direction

Start with the TypeScript reproduction's Provider and onEventHandler path, then run cdk-synth and inspect the generated CloudFormation template. The change is done when the framework-created onEvent Lambda uses the latest intended Node.js runtime instead of nodejs22.x, while the supplied user function remains unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, node.js, typescript
Domain
cloud, devops
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.