The Problem:
AWS Lambda functions using AwsCustomResource
and the Node.js 12.x runtime are no longer supported. How can the runtime value be specified in this scenario?
The Solutions:
Solution 1: Custom Resource handlers upgraded to NodeJS 14
Custom Resource handlers have been upgraded to Node.js 14 in CDK version 2.28. You will need to update your project to use this version or a later version of the CDK to continue using Custom Resources.
Solution 2: Upgrade CDK
End of support for Node.js 12.x was announced in May. To use the latest version of the Node.js runtime, upgrade the AWS CDK version to at least 2.28.0.
To override the runtime version using an escape hatch, follow these steps:
- Find the SingletonLambda object for AwsCustomResource.
- Get the CfnFunction object.
- Use addPropertyOverride to set the Runtime property to the desired value.
Note: Ensure that the Lambda code is compatible with the newer Node.js version before using this escape hatch.
Solution 3: Upgrading CDK Versions
Upgrading the following packages to the specified versions can resolve the issue:
- "@types/node": "^20.3.2"
- "aws-cdk": "^2.85.0"
- "ts-node": "^10.9.1"
- "aws-cdk-lib": "^2.85.0"
- "cdk": "^2.85.0"
Q&A
In our project we are using AwsCustomResource, how can we specify the value of the runtime?
CDK already upgraded from NodeJS 12 since 2.28, so if you updated to the latest version, you should be using NodeJS 16.
How was the Custom Resource handlers upgraded?
From NodeJS 12 back in CDK 2.28
How to change the runtime of a Lambda function?
You can’t change it manually, it’s handled automatically by the CDK.