Skip to content

RDS Data Source - Lambda with old Node.js version 18

0

Hi, In CloudWatch -> Settings I have created a new Metric Data Source - Amazon RDS PostgreSQL. The resources will be added using a CloudFormation template from AWS. It creates also a Lambda function, wich uses Node.js in version 18.x. Node.js 18 is currently End of Support. Editing the runtime in Lambda settings to the newer version 20 or 22 causes, that the Datasource cannot connect to the RDS more. How to solve that issue? It is planned to update this template by AWS, so that the Lambda function will run on a newer version of Node.js?

1 Answer
0
Accepted Answer

When upgrading your Lambda function from Node.js 18.x to newer versions like 20.x or 22.x, you're encountering connectivity issues with your RDS PostgreSQL data source. This is happening because of a significant change in how Node.js runtimes handle certificates in Lambda.

In Node.js 18.x and earlier versions, Lambda automatically loaded Amazon-specific CA certificates, including those needed for RDS connections. However, starting with Node.js 20.x, Lambda no longer loads these additional CA certificates by default.

To resolve this issue when upgrading to Node.js 20.x or later, you need to:

  1. Set the NODE_EXTRA_CA_CERTS environment variable to /var/runtime/ca-cert.pem in your Lambda function configuration. This will restore the same certificate loading behavior that existed in Node.js 18.x.

  2. For optimal performance, consider bundling only the specific certificates you need with your deployment package and loading them via the NODE_EXTRA_CA_CERTS environment variable. For example, you could include the required RDS certificates alongside your code as certificates/rds.pem and set NODE_EXTRA_CA_CERTS to /var/task/certificates/rds.pem.

Regarding AWS updating the CloudFormation template, while there's no specific information about planned updates to this particular template, AWS typically updates their templates to support newer runtimes as older ones approach deprecation. However, you don't need to wait for an official template update - you can modify your existing template to use a newer runtime and add the necessary environment variable configuration to maintain RDS connectivity.
Sources
Building Lambda functions with Node.js - AWS Lambda

answered a year ago

AWS
EXPERT

reviewed a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.