The runtime parameter of nodejs12.x is no longer supported for creating or updating AWS Lambda functions while using AwsCustomResource – Aws-lambda

by
Ali Hasan
aws-cdk aws-cloudformation-custom-resource aws-lambda

Quick Fix: AWS CDK 2.28 and later use NodeJS 14 for Custom Resource handlers and no longer support NodeJS 12. Upgrade your CDK version to 2.28 or later to resolve this issue.

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:

  1. Find the SingletonLambda object for AwsCustomResource.
  2. Get the CfnFunction object.
  3. 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.