Cannot connect to aws rds using postgres and sqlalchemy

Viewed 28

I create a db instance in aws rds with Easy create (which offers default and recommended config), then I made the Publicly accessible to true. When I try to connect using my fastapi app and the code:

from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker

SQLALCHEMY_DATABASE_URL = "postgresql://USER:PASSWORD@HOST/DB"

engine = create_engine(SQLALCHEMY_DATABASE_URL)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)

Base = declarative_base()

It shows in the error:

    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) connection to server at "database-1.cshqjmfxxxxx.eu-central-1.rds.amazonaws.com" (3.72.174.85), port 5432 failed: Connection timed out (0x0000274C/10060)
        Is the server running on that host and accepting TCP/IP connections?

The configuration of the db instance are:

enter image description here

0 Answers
Related