Python 3.x Amazon Web服务RDS的读/写URI

Python 3.x Amazon Web服务RDS的读/写URI,python-3.x,amazon-web-services,sqlalchemy,load-balancing,haproxy,Python 3.x,Amazon Web Services,Sqlalchemy,Load Balancing,Haproxy,我正在使用HAProxy为我的应用程序进行AWS RDS(MySQL)负载平衡,这是使用Flask编写的 HAProxy.cfg文件具有以下数据库配置 listen mysql bind 127.0.0.1:3306 mode tcp balance roundrobin option mysql-check user haproxy_check option log-health-checks server db01 MASTER_DATABSE_ENDPOINT.rds.amazonaws.

我正在使用HAProxy为我的应用程序进行AWS RDS(MySQL)负载平衡,这是使用Flask编写的

HAProxy.cfg文件具有以下数据库配置

listen mysql
bind 127.0.0.1:3306
mode tcp
balance roundrobin
option mysql-check user haproxy_check
option log-health-checks
server db01 MASTER_DATABSE_ENDPOINT.rds.amazonaws.com
server db02 READ_REPLICA_ENDPOINT.rds.amazonaws.com
我正在使用SQLALCHEMY,它的URI是:

SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://USER:PASSWORD@127.0.0.1:3306/DATABASE'
但是,当我在测试环境中运行API时,仅从DB读取内容的API执行得很好,但向DB写入内容的API给我的错误主要是:

(pymysql.err.InternalError) (1290, 'The MySQL server is running with the --read-only option so it cannot execute this statement')
我想我现在需要在这个场景中使用两个URL,一个用于
只读
操作,另一个用于
写入

这是如何与烧瓶和SQLALCHEMY与HAProxy一起工作的? 我如何告诉我的应用程序使用一个URL进行
write
操作和其他
HAProxy
URL进行
read-only
操作

我没有从SQLAlchemy的文档中找到任何帮助。

SQLAlchemy可以轻松连接到多个数据库。达到 它预先设定了炼金术以支持多个“绑定”

关于约束:

db.create_all(bind='read') # from read only
db.create_all(bind='master') # from master

SQLAlchemy可以轻松连接到多个数据库。达到 它预先设定了炼金术以支持多个“绑定”

关于约束:

db.create_all(bind='read') # from read only
db.create_all(bind='master') # from master

我试过了,但是我的应用程序如何知道哪个URI用于
读取
,哪个URI用于
写入
?使用
bind='master'
,你需要告诉你的应用程序写入master,因为你无法写入读取replicasOkay。你的意思是在编写
的API中使用
bind='master'
?我试过了,但我的应用程序如何知道读取
时使用哪个URI,写入
时使用哪个URI?使用
bind='master'
,你需要告诉你的应用程序向master写入,因为你不能写读replicasOkay。您的意思是在编写
的API中使用
bind='master'