skip to Main Content

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()

Endpoint and port
Database name, username and password

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


  1. You have not specified the port inside the psycopg2 connect function.

    Login or Signup to reply.
  2. 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:

    • Create a new Security Group in the Amazon EC2 management console
    • Add an Inbound rule on Port 5432 from your IP address (or 0.0.0.0/0, which is the whole Internet, but that is much less secure)
    • In the Amazon RDS management console, Modify the database and change the security group to this new security group (and remove the default security group)
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search