Read/read-write Uris For Amazon Web Services Rds
I am using HAProxy to for AWS RDS (MySQL) load balancing for my app, that is written using Flask. The HAProxy.cfg file has following configuration for the DB listen mysql bind 127.
Solution 1:
Flask-SQLAlchemy can easily connect to multiple databases. To achieve that it preconfigures SQLAlchemy to support multiple “binds”.
SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://USER:PASSWORD@DEFAULT:3306/DATABASE'
SQLALCHEMY_BINDS = {
'master': 'mysql+pymysql://USER:PASSWORD@MASTER_DATABSE_ENDPOINT:3306/DATABASE','read': 'mysql+pymysql://USER:PASSWORD@READ_REPLICA_ENDPOINT:3306/DATABASE'
}
Referring to Binds:
db.create_all(bind='read') # from read only
db.create_all(bind='master') # from master
Post a Comment for "Read/read-write Uris For Amazon Web Services Rds"