How to connect to AWS RDS MySql database with Python

Question:

I am currently trying to connect to my MySql database created on AWS with a python program using the library PyMySQL

When I run the above code I get the following error:

What am I doing wrong? The arguments I gave to the function are correct. Could it be a problem with the MySql driver?

Answer:

If you want to access your RDS from outside of AWS over internet, than it should be set to be publicly available:

enter image description here

Also it should be placed in a public subnet (e.g. default VPC) and have opened inbound rules in its security group (good practice is to limit access to only selected IPs or IP range, rather then using 0.0.0.0/0):

enter image description here

Hope this helps.

Leave a Reply