- Newest
- Most votes
- Most comments
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:
-
Set the
NODE_EXTRA_CA_CERTSenvironment variable to/var/runtime/ca-cert.pemin your Lambda function configuration. This will restore the same certificate loading behavior that existed in Node.js 18.x. -
For optimal performance, consider bundling only the specific certificates you need with your deployment package and loading them via the
NODE_EXTRA_CA_CERTSenvironment variable. For example, you could include the required RDS certificates alongside your code ascertificates/rds.pemand setNODE_EXTRA_CA_CERTSto/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
