Connect to RDS using Python & SSL

Ahmed Musaad
Ahmed Musaad
Connect to RDS using Python & SSL

I found myself trying to connect to a RDS instance from a Python script while maintaining SSL encryption. The official documentation was a bit vague on how to do this so I spent some time digging and eventually found how it can be done. The following scripts provides a simple example of how to create and use such a connection.

Before you can run the script you need to download the CA certificate bundle file from Amazon (Link)

import mysql.connector

SSL_CA='rds-combined-ca-bundle.pem'
user='<user>'
password='<password>'
host='<rds instance endpoint>'
database='<database name>'

cnx = mysql.connector.connect(user, password, host, database, ssl_ca=SSL_CA)

cnx.close()

That's it, you are now connected to the RDS database and ready to do all types of great things.

Script from Technowise (with minor edits)



Great! Next, complete checkout for full access to Ahmed Musaad
Welcome back! You've successfully signed in
You've successfully subscribed to Ahmed Musaad
Success! Your account is fully activated, you now have access to all content
Success! Your billing info has been updated
Your billing was not updated