0

I want to connect to postgres in Aws server. I have installed "pg" to node. I have tried to use the connection String, but there is no way to add private key there. So I also try with

const pool = new Pool({
  user: 'dbuser',
  host: 'database.server.com',
  database: 'mydb',
  password: 'secretpassword',
  port: 3211,
  privateKey : require('fs').readFileSync('./ssh_keys/my_key')
})

In both cases I get connection refused.

Jorge Monroy
  • 408
  • 1
  • 5
  • 16
  • You can do this via SSH tunnel. Check out this answer: https://stackoverflow.com/a/16838293/4045206 Important thing to note is this part `1111:localhost:5432` - once the tunnel is open, you will be connecting to localhost on port 1111 (does not have to be 1111) – wfunston Apr 01 '19 at 03:54
  • Could you please describe your configuration some more? For example, from where are you trying to make the connection -- from your own computer (outside of AWS)? Is PostgreSQL running on an Amazon EC2 instance, or is it using Amazon RDS? Is the database accessible from the Internet? Why are you wanting to SSH into a database? Feel free to Edit your question to provide more details. – John Rotenstein Apr 01 '19 at 04:10
  • Make sure that the security group assigned to the DB instance has rules to allow access through any firewall your connection might go through. For example, if the DB instance was created using the default port of 5432, allow it in the security group of your DB instance. – Aress Support Apr 01 '19 at 17:03

0 Answers0