node.jspostgresqlamazon-elastic-beanstalkamazon-rdspg

RDS connect ETIMEDOUT 172.31.16.58:5432


I am trying to build a mock data rest api using node/ express and RDS. when the server is running locally, I do receive a response from the DB when I send a get request using the browser or postman . so my local app is able to connect to the DB I have hosted on RDS.

but after I deploy my server to elastic beanstalk, I cant get a response back from the DB. and in the logs I get this error

Error: connect ETIMEDOUT 172.31.16.58:5432
May  2 12:46:18 ip-172-31-30-93 web: at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1494:16) {
May  2 12:46:18 ip-172-31-30-93 web: errno: -110,
May  2 12:46:18 ip-172-31-30-93 web: code: 'ETIMEDOUT',
May  2 12:46:18 ip-172-31-30-93 web: syscall: 'connect',
May  2 12:46:18 ip-172-31-30-93 web: address: '172.31.16.58',
May  2 12:46:18 ip-172-31-30-93 web: port: 5432
May  2 12:46:18 ip-172-31-30-93 web: }

this is my DB connection:

const Pool = require("pg").Pool;
require("pg").defaults.debug = true;
const pool = new Pool({
  user: "postgres",
  password: "*********",
  host: "mock-db.c5rxzfyu3kp.eu-west-2.rds.amazonaws.com",
  port: 5432,
  database: "mockDB",
});

export { pool };

security group inbound configuration for beanstalk

security group outbound configuration for beanstalk

[RDS security group](https://i.sstatic.net/t5CJQ.png)

RDS security group

I am sure sure the server is working on elastic beanstalk because when I send a request to the server that doesnt involve the DB I get a response.

Ive tried changing the security groups for the elastic beanstalk and the DB


Solution

  • I was able to solve this by allowing all traffic on the outbound policy on my DBs security group .