# Express + Knex + RDS (postgres) = Internal server error?

**URL:** <https://forum.serverless.com/t/express-knex-rds-postgres-internal-server-error/6871>\
**Category:** Serverless Framework\
**Tags:** aws\
**Created:** [January 3, 2019, 4:30am UTC](https://forum.serverless.com/t/express-knex-rds-postgres-internal-server-error/6871 "2019-01-03T04:30:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomlum](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/tomlum/32/2891_2.png) [@tomlum](https://forum.serverless.com/u/tomlum)\
**Post date:** [January 3, 2019, 4:30am UTC](https://forum.serverless.com/t/express-knex-rds-postgres-internal-server-error/6871/1 "2019-01-03T04:30:20Z")

</div>

Hey all. Pretty new to this so apologies if I misspeak on anything.

Right now I’m using serverless-http to run my express app. I’m able to ping a simple hello world endpoint from postman, however whenever I attempt to connect to my RDS through Knex, I always timeout (around 6 seconds) and get an “Internal Service Error”.

My vpc in my serverless.yaml is set with the appropriate securityGroupIds/subnetIds

```
provider:

```

name: aws  
runtime: nodejs8.10  
region: us-east-1  
vpc:  
securityGroupIds:  
- sg-########  
subnetIds:  
- subnet-########  
- subnet-########  
- subnet-########  
- subnet-########  
- subnet-########  
- subnet-########

Does anyone know what could be the issue, whether with rds or serverless? As well, does anyone have any tips on debugging issues like this that give the opaque internal server error? Much appreciated!

---

<div class="post-metadata">

**Author:** ![jeremydaly](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/jeremydaly/32/2104_2.png) [@jeremydaly](https://forum.serverless.com/u/jeremydaly)\
**Post date:** [January 3, 2019, 12:37pm UTC](https://forum.serverless.com/t/express-knex-rds-postgres-internal-server-error/6871/2 "2019-01-03T12:37:09Z")

</div>

Make sure you are logging your errors and then take a look at CloudWatch logs to see what the issue is. It sounds like your Lambda is throwing errors that you’re not catching, so an invalid response is being sent to API Gateway.

Also, look at using the serverless-offline plugin so that you can run your API locally. You can either connect to a local database, or use a VPN or SSH tunnel to connect to your remote one for testing.

---

<div class="post-metadata">

**Author:** ![tomlum](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/tomlum/32/2891_2.png) [@tomlum](https://forum.serverless.com/u/tomlum)\
**Post date:** [January 3, 2019, 3:24pm UTC](https://forum.serverless.com/t/express-knex-rds-postgres-internal-server-error/6871/3 "2019-01-03T15:24:26Z")

</div>

Ah yes I forgot to mention that the app works fine when running on serverless-offline and a local postgres instance, which is why I suspect it is something to do with rds/vpc configuration.

As well, I attempted to console log like

```
   try{
       console.log(1)
       Knex Call
   }
   catch{
       console.log(2)
   }

```

I don’t see console.log(2) when I tail via sls logs

I will check cloudwatch later today, thanks for the tips

---

<div class="post-metadata">

**Author:** ![tomlum](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/tomlum/32/2891_2.png) [@tomlum](https://forum.serverless.com/u/tomlum)\
**Post date:** [January 3, 2019, 11:42pm UTC](https://forum.serverless.com/t/express-knex-rds-postgres-internal-server-error/6871/4 "2019-01-03T23:42:38Z")

</div>

Yeah, no errors are present or loggable. I imagine it’s a timeout/connection issue. My handler looks like

```
    module.exports.handler = async (event, context) => {
	context.callbackWaitsForEmptyEventLoop = false
  return await handler(event, context);
};

```

so callbackWaitsForEmptyEvenyLoop shouldn’t be causing the issue.  
Do you know what the error could be?
