2

My function works locally, but, when I deploy to AWS Lambda, it can't seem to connect to my postgres database. Here's the error:

{ [Error: connect ECONNREFUSED] code: 'ECONNREFUSED', errno: 'ECONNREFUSED', syscall: 'connect' }, isOperational: true, code: 'ECONNREFUSED', errno: 'ECONNREFUSED', syscall: 'connect' }

My database is hosted on an Azure virtual machine, and I'm not having problems connecting to it from any other app nor from this app when run locally. What could be causing the connection to fail when running on Lambda?

3
  • Some sort of firewall? Commented Dec 23, 2015 at 15:36
  • @Michelem Amazon says they limit traffic on TCP port 25 and that they limit outbound traffic to TCP. They manage inbound. I changed my connection string from postgres:// to tcp:// but that didn't seem to help. Commented Dec 23, 2015 at 15:59
  • You should try to nmap the Postgres port from the lambda server check if you can reach it: nmap -p 5432 <postgres-hostname> Commented Dec 24, 2015 at 7:08

1 Answer 1

3

It turned out to be something dumb. I am using node-lambda and thought the .env file it creates was propagated to the function's environment. Logging my DB connection string showed this wasn't the case. Once I set that, everything was golden.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.