Search code examples
postgresqlmacosamazon-web-servicesterminalrds

I cant connect to AWS RDS using Postgres


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.


Solution

  • 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.