Issue | Connecting Lambda to RDS

Problem Statement:

  • I am trying to connect Lambda to RDS but my connection to DB times out and connection does not go through successfully.
  • My RDS is not in Amazon VPC and my lambda is in Amazon VPC.

Tried Solution:

  • I added VPC settings to my lambda so that it can have a static IP according to the link here
  • Once my lambda was assigned a static IP, i added it to the DB security group of RDS to whitelist the IP. But the connection still keeps on timing out.

Can anyone help me out with this?

Thanks in advance!

My RDS is not in Amazon VPC and my lambda is in Amazon VPC.

This is going to cause you lots and lots of pain.

Can your Lambda function communicate to the Internet? That’s what it will need to even attempt a connection to your RDS instance, if it’s not in your VPC.

This sounds like a very non-standard, complicated, and probably insecure setup (e.g. public-facing database), is there any chance you can simplify it?


If you are using NodeJS, try this, this solved a similar issue with RDS/Postgre:

exports.handler = (event, context, callback) => {

  context.callbackWaitsForEmptyEventLoop = false;

  • Jari