Not able to connect to RDS via code

0

Hi, I created a postgres RDS database which I configured and was able to connect via pgAdmin. However when I try to connect to the db via code, I get timeout error

For context my vpc security group rules are as follows

Security Groups

2 Answers
1

Hi,

  1. Did you check that the TCP port used by your RDS instance matches the one in your Sec Group? If not, you requests will not go through the sec group.

  2. Does your RDS instance have a public IP address to access it over the internet from a remote machine ?

Best,

Didier

profile pictureAWS
EXPERT
answered 17 days ago
profile picture
EXPERT
reviewed 17 days ago
EXPERT
reviewed 17 days ago
  • Please check the configs shared below and see if I missed anything

  • Any update?

0

1.As Shown in the rds config screenshot. The port is 5432. In the security group config ss added, 5432 port is added in security groups. Also rds is publicly available RDS Config

For additional context I am sharing the code here which I use to connect to postgres db

import psycopg2

# Database connection details
db_host = 'my endpoint'
db_port = '5432'
db_name = 'sqltrainingdb'
db_user = 'postgres'
db_password = 'password'

# Establish a connection to the database
conn = psycopg2.connect(
    host=db_host,
    port=db_port,
    dbname=db_name,
    user=db_user,
    password=db_password
)

conn

And the error I get is Error

Ahsan
answered 17 days ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions