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")
My Code Looks Like This:
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()
The Flask-SQLAlchemy documentation says that the format of the SQLALCHEMY_DATABASE_URI for mysql database connections should look like this:
mysql://username:password@server/db
Additionally, I can check the AWS RDS console for information on my database instance. The console looks like this.
Right now I am assuming that "username" in SQLAlchemy refers to the "Master Username" in the AWS RDS console, "server" in SQLAlchemy refers to the "Endpoint" in the AWS RDS console, and "db" refers to the "Database Instance Name"
What am I doing wrong??
If someone could describe the SQLALCHEMY_DATABASE_URI for me with the AWS RDS console terms, that would completely solve the problem.