title: Can't connect to AWS DB from locally-hosted Node.js app
body: <p>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.</p>
  <p>My app is an Azure Function and looks like this:</p>
  <pre><code>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) =&gt; {
      //...todo
  }
  </code></pre>
  <p>When I run it, via <code>func start</code>, I get this:</p>
  <p><a href="https://i.stack.imgur.com/9jCqL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9jCqL.png" alt="enter image description here" /></a></p>
  <p>If I take Azure out of the equation, and just run the script manually, via</p>
  <pre><code>node path/to/script/js
  </code></pre>
  <p>...I instead get:</p>
  <p><a href="https://i.stack.imgur.com/WrS2E.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WrS2E.png" alt="enter image description here" /></a></p>
  <p>If I set <code>ssl</code> to <code>false</code> and run as above, I get:</p>
  <p><a href="https://i.stack.imgur.com/i6Gee.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/i6Gee.png" alt="enter image description here" /></a></p>
  <p>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.</p>
  <p>Possibly related: I have tried to set up an API Connection within the Azure Portal to my DB and that fails to connect also.</p>
  <p>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.</p>
  <p>Thanks very much in advance.</p>