I cant connect to AWS RDS using Postgres
Asked Answered
D

2

8

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.

Doorbell answered 17/5, 2020 at 12:48 Comment(0)
C
7

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.

Clad answered 17/5, 2020 at 14:26 Comment(2)
Thanks! Problem fixed by turning on public accessibility! I assumed this meant there would be no security for the instance rather than allowing public IPs access (???). Theres a lot more to learn it seems! Thanks againDoorbell
Also note that you will need to create a Security Group that allows the instance to be public. Here's how to do it: https://mcmap.net/q/459498/-aws-rds-for-postgresql-cannot-be-connected-after-several-hoursInterject
T
1

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

Tsana answered 17/5, 2020 at 12:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.