'Error while using Python to connect to Amazon RDS Postgresql database

I'm trying to connect to Amazon RDS Postgresql database with this python code

import psycopg2
engine = psycopg2.connect(
    database="vietop2database",
    user="postgres",
    password="07041999",
    host="vietop2.cf4afg8yq42c.us-east-1.rds.amazonaws.com",
    port='5433'
)
cursor = engine.cursor()
print('opened database successfully')

I encountered an error:

could not connect to server: Connection timed out
    Is the server running on host "vietop2.cf4afg8yq42c.us-east-1.rds.amazonaws.com" (54.161.159.194) and accepting
    TCP/IP connections on port 5433?

I consulted this trouble shooting on amazon and I already make sure the DB instance's public accessibility is set to Yes to allow external connections. I also changed port to 5433 and set VPC security to default. Yet, I fail to connect to the database. What might be the reasons? Please help me. Thank you very much

Below are the database connectivity and configuration information

enter image description here

enter image description here



Solution 1:[1]

I found the answer. I need to add new inbound rule allowing all traffic of IPv4 type

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 thanh pham