1
votes

I created an RDS instance (Postgres, free tier, in default VPC) and selected public access. Now, I am trying to connect to it in Python like this:

import psycopg2 as ps
# define credentials 
credentials = {'POSTGRES_ADDRESS' : '', # change to your endpoint
               'POSTGRES_PORT' : '', # change to your port
               'POSTGRES_USERNAME' : '', # change to your username
               'POSTGRES_PASSWORD' : '', # change to your password
               'POSTGRES_DBNAME' : ''} # change to your db name
# create connection and cursor    
conn = ps.connect(host=credentials['POSTGRES_ADDRESS'],
                  database=credentials['POSTGRES_DBNAME'],
                  user=credentials['POSTGRES_USERNAME'],
                  password=credentials['POSTGRES_PASSWORD'],
                  port=credentials['POSTGRES_PORT'])
cur = conn.cursor()

Here is the security group inbound: enter image description here

enter image description here

enter image description here

However, this times out. What am I doing wrong? I believe I put in all the credentials above, so maybe it is a problem with the AWS side of things? Please let me know if you need any more info.

Thanks!

2
Comments are not for extended discussion; this conversation has been moved to chat. - Samuel Liew

2 Answers

4
votes

You will need to allow inbound access on the Security Group:

  • Port 5432
  • Source: Your IP address (for good security)

It is best to create a new Security Group with these settings then modify the database to use this new security group. That way, it will not impact other systems, and future changes will not impact this security group.

See also: Change security group on AWS RDS Database Instance

2
votes

Based on the comments.

The issue turned out to be due to missing default database in the RDS.

Recreating the RDS with the default database solved the problem.