I cant connect to AWS RDS using Postgres

8.9k views Asked by At

Ive created an instance/database on aws and when I try to connect to it through my terminal, by running the code below, I get an error.

The line I run in the terminal is:

psql --host=testdb.c7hgibdbsgjm.eu-west-2.rds.amazonaws.com --port=5432 --username=postgres --password --dbname=testdb

And the error it returns is:

psql: error: could not connect to server: could not translate host name "testdb.c7hgibdbsgjm.eu-west-2.rds.amazonaws.com" 
to address: nodename nor servname provided, or not known. 

Ive spent the last 3 days reading the relevant documentation and trying to get this to work but I don't know where im going wrong.

Also when I run:

nslookup testdb.c7hgibdbsgjm.eu-west-2.rds.amazonaws.com

It returns:

Non-authoritative answer:
*** Can't find testdb.c7hgibdbsgjm.eu-west-2.rds.amazonaws.com: No answer

I come from a statistics background and I've done a fair bit of coding in R and python but Im relatively new to using the terminal etc!

Thanks for any guidance or help as this is making me want to punch my laptop.

2

There are 2 answers

2
kadamb On BEST ANSWER

On running dig command: dig testdb.c7hgibdbsgjm.eu-west-2.rds.amazonaws.com

It returned a private IP: 172.31.23.42.

It seems you are running RDS instance as private or internal, i.e. it won't be accessible from the internet.

You need to access it from the VPC itself or need to use a VPN.

0
Chris Williams On

Seems like its a DNS resolution issue. I was able to resolve it using DIG.

In the VPC make sure that both of the following options are enabled on the VPC:

  • enableDnsHostnames
  • enableDnsSupport

If the RDS instance is not hosted in the VPC but is instead accessed across a VPC peer then DNS resolution might need enabling on the VPC peer