I'm running a locally-hosted (i.e. on my machine) Node.js app and am trying to connect it to a remote AWS-hosted Postgres DB.
My app is an Azure Function and looks like this:
const { Client } = require('pg');
const client = new Client({
host: '*******.eu-west-1.compute.amazonaws.com',
port: 5432,
user: '********',
password: '************',
database: '************',
ssl: true
})
client.connect();
module.exports = async (ctx, req) => {
//...todo
}
When I run it, via func start, I get this:
If I take Azure out of the equation, and just run the script manually, via
node path/to/script/js
...I instead get:
If I set ssl to false and run as above, I get:
The credentials are definitely correct. If I use the same credentials to connect to the DB via a DB client such as Heidi SQL or DBeaver, it connects fine. It even connects from my locally-running Rails app. So something is preventing Node from connecting to it.
Possibly related: I have tried to set up an API Connection within the Azure Portal to my DB and that fails to connect also.
There is nothing I can see on the AWS DB itself to suggest why this should happen, but I'm no server admin so perhaps there's some security setting I need to change.
Thanks very much in advance.


