Skip to content

how to connect to a rds database via python?

0

I have set up a rds database (aurora postgresql) and a rds proxy . i have a proxy endpoint as such - somedatabase-proxy.proxy-2ufoahofioie.us-west-1.rds.amazonaws.com. I want to connect to this database and perform read/write operations via my python code , either running in lambda or ec2 instance.

is there a certain library , i can use to connect to the database and issue sql commands ?

new to this , so would like some sample code .

asked 2 years ago1.8K views
1 Answer
1

You'll need the boto3 library.

AWS gives some sample Python code to connect to MariaDB/MySQL and to PostgeSQL at https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/UsingWithRDS.IAMDBAuth.Connecting.Python.html

As you say you are new to this, be sure that you read the link to the page about Credentials, and you'll also need a basic understanding of IAM.

Once connected, database queries and extracting data should be like working with any other database.

EXPERT
answered 2 years ago
EXPERT
reviewed 2 years ago
AWS
EXPERT
reviewed 2 years ago
  • thank you, I don't understand why we need to generate a token , to access this and based on the link you provided , where do i find the path to the ssl certificate for rds. I'm using aurora serverless (postgresql compatible) and have a rds proxy as well. . alternatively, can we use psycopg2 library for python? My app is python based and plan to run in some ec2 container or via ECS service. any examples you can point me to?

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.