Issue connecting to postgres on AWS SAM?

Sep 21, 2020

šŸ¤” Problem

I'm trying to connect my lambda to a local instance of postgres. However, I'm getting the following error.

{
Error: connect ECONNREFUSED 127.0.0.1:5432
  ...
  ...
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 5432
}

āœ… Solution

I resolved this issue by replacing localhost with host.docker.internal.

Docker docs for reference

A handsome man.

I'm Wesley. I live in Boston and work on Wonderment.

Go back to home