I am attempting to use node js to access my postgresql database hosted on AWS RDS by using a query. Here is my code:
const {Client} = require('pg');
const client = new Client({
user: '*****',
host: '******',
database: '******',
password: '*******',
port: 5432, // Default PostgreSQL port
ssl: {rejectUnauthorized: false }
});
client.connect();
client.query('select * from persons', (err, res)=> {
if (!err)
{
console.log(res.rows);
}
else
{
console.log(err.message);
}
});
I have starred out the credentials but I know there are correct because this code runs as expected on my EC2 instance, but when trying to run it on my local machine, it gives a timeout error. This error is occurring on the query line. I have checked my rules for the security group which this RDS instance belongs to and it is set to allow inbound and outbound connections from postgresql on port 5432 from any IP.