# Issue | Connecting Lambda to RDS

**URL:** https://forum.serverless.com/t/issue-connecting-lambda-to-rds/2935
**Category:** Serverless Framework
**Tags:** aws
**Created:** [October 23, 2017, 10:01pm UTC](https://forum.serverless.com/t/issue-connecting-lambda-to-rds/2935 "2017-10-23T22:01:03Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![aneeq](https://avatars.discourse-cdn.com/v4/letter/a/b5a626/32.png) [@aneeq](https://forum.serverless.com/u/aneeq)
#### Post date: [October 23, 2017, 10:01pm UTC](https://forum.serverless.com/t/issue-connecting-lambda-to-rds/2935/1 "2017-10-23T22:01:04Z")

</div>

**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](http://techblog.financialengines.com/2016/09/26/aws-lambdas-with-a-static-outgoing-ip/)
- 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!

---

<div class="post-metadata">

### Author: ![rowanu](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/rowanu/32/75_2.png) [@rowanu](https://forum.serverless.com/u/rowanu)
#### Post date: [October 26, 2017, 9:19pm UTC](https://forum.serverless.com/t/issue-connecting-lambda-to-rds/2935/2 "2017-10-26T21:19:01Z")

</div>

> 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?

---

<div class="post-metadata">

### Author: ![Jari](https://avatars.discourse-cdn.com/v4/letter/j/9de0a6/32.png) [@Jari](https://forum.serverless.com/u/Jari)
#### Post date: [October 27, 2017, 5:45am UTC](https://forum.serverless.com/t/issue-connecting-lambda-to-rds/2935/3 "2017-10-27T05:45:03Z")

</div>

Hi,

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

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

  context.callbackWaitsForEmptyEventLoop = false;
...

```

[http://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-context.html](http://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-context.html)

- Jari
