Connect to AWS RDS Postgres database with python Connect to AWS RDS Postgres database with python postgresql postgresql

Connect to AWS RDS Postgres database with python


Thank's John Rotenstein for your comment.

As he pointed out, my-rds-table-name is the database instance name, not the database name, the default database name is postgres.

import psycopg2engine = psycopg2.connect(    database="postgres",    user="my_user_name",    password="abc123def345",    host="my-rds-table-name.123456.us-east-1.rds.amazonaws.com",    port='5432')


Using sqlalchemy you can do the following:

engine = create_engine('postgresql://postgres:postgres@<AWS_RDS_end-point>:5432/postgres')

Then you can update your database.For example:

df = pd.DataFrame({'A': [1,2], 'B':[3,4]})df.to_sql('tablename', engine, schema='public', if_exists='append', index=False)