For my Flask app, I want to use the Flask-SQLAlchemy extension to connect to a database instance I created on AWS RDS.
When I try to connect, the application times out and I get the following error:
sqlalchemy.exc.OperationalError: (OperationalError) (2003, "Can't
connect to MySQL server on
'xxxxxxxxxxxxxxx.xxxxxxxxxxxx.us-east-1.rds.amazonaws.com'(60")
from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy
application = Flask(__name__)
application.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://{master username}:{db password}@{endpoint}/{db instance name}'
db = SQLAlchemy(application)
@application.route('/')
def hello_world():
return 'Hello World'
if __name__ == '__main__':
application.run()
mysql://username:password@server/db
Go to your AWS RDS console and choose your instance -> DB Security Groups -> Click Default
and add a new CIDR as per the recommended IP range.
This is basically a firewall configuration which determines who can connect to the database instance.
You could set it as 0.0.0.0/0 so that firewall doesn't prevent you from accessing it from any host/network.