connecting to AWS RDS from nodejs local machine

I have been getting connect ETIMEDOUT 172.31.97.43:5432 error while trying to test my nodejs express app with postgres database running on my local machine to connect to AWS RDS.

I have done the necessary settings on the AWS RDS like;

MY Connection setup looks this in database.ts file:

import {Pool}  from "pg";

export const client = new Pool({
    host     : 'omerenma.cs6txkhiualn.us-east-1.rds.amazonaws.com',
    user     : '********',
    password : '********',
    port     : 5432,
    connectionTimeoutMillis:30000
  })

client.connect(function(err) {
    if (err) {
      console.error('Database connection failed: ' + err.stack);
      return;
    }
  
    console.log('Connected to database.');
  });



***client.end()***

Error screenshot

Upvotes: 0

Views: 2398

Answers (2)

Manish Doley
Manish Doley

Reputation: 1

The solution was to delete the vpc (default vpc as well) which in turn deletes all the subnets and security groups and freshly setting up everything freshly

Things to keep in mind

  1. The inbound rule should have 0.0.0.0/0
  2. The database instance should be Publicly accessible

If nothing works delete the vpc and create a new one and then the above points

Upvotes: 0

Haven spent time going through my AWS RDS setup, I realized the following:

1 I had too many vpc that were conflicting with others 2 My security groups where also conflicting 3 My node version is 18+ and by default has an Ipv6 where as AWS RDS listens to Ipv4 4 My inbound rules was not properly configured

Solutions: 1 I deleted all the vpc including the default vpc and created a new default vpc 2 I configured my Inbound rules to listen for Ipv4 and Ipv6 and to also listen for all traffic within ipv4 and ipv6. 3 I adjusted my security groups appropriately This was the fix and my nodejs server can now connect to AWS RDS

Upvotes: 0

Related Questions