I have created a AWS RDS PostgreSQL instance with public access enabled but I am unable to connect to it. Here is my code:
try:
conn = psycopg2.connect(dbname="elevate_permission",
user="postgres",
password="password123",
host="database-1.ce2ilrafe9ry.ap-southeast-1.rds.amazonaws.com")
print("Connected to DB")
except psycopg2.OperationalError as e:
logger.error(e)
sys.exit()
EDIT
I’ve added the above exception to my code above, this is the error message I receive:
Operation timed out. Is the server running on that host and accepting TCP/IP connection?
2
Answers
You have not specified the port inside the psycopg2 connect function.
The screenshot showing your Security Group is indicating that you are using a Security Group called
default
. It is unlikely to be permitting an Inbound connection on port 5432 (which is used by Postgres).I recommend the following:
0.0.0.0/0
, which is the whole Internet, but that is much less secure)default
security group)