aws-rds-proxy-sqlalchemy
記錄使用 sqlalchemy 透過 PyMySQL 連線到 RDS proxy 遇到的問題
進行 ssl/tls 連線的方式
- 設定 ssl_args
- code example
ssl_args = {'ssl': {'use': True}} echo_sql = True if os.environ.get('SQLALCHEMY_ECHO') == 'true' else False engine = db.create_engine(conn_sqlalchemy_str, echo=echo_sql, poolclass=NullPool, connect_args=ssl_args)
連線到 RDS proxy 解法
- 遇到的問題
- 有使用
rds_client.generate_db_auth_token
取得 token,不過連到 DB 還是會出現 [ERROR] OperationalError: (pymysql.err.OperationalError) (1045, "Access denied for user 'master'@'172.31.58.218' (using password: NO)")
- 有使用
- 解法
- 關閉 IAM auth 的方式,改為使用傳統的 auth
Reference
- rds-proxy-python-lambda/rds-proxy.py at master · MbuguaFrancis/rds-proxy-python-lambda
- 在SQLAlchemy中使用SSL - PYTHON _程式人
- Using Amazon RDS Proxy with AWS Lambda | AWS Compute Blog
- Have your Lambda Functions Connect to RDS through RDS Proxy | by Michael Zaghi | AWS in Plain English
- Use AWS Lambda with RDS Proxy and IAM authentication | Medium
- Connection Object — PyMySQL 0.7.2 documentation
ssl – A dict of arguments similar to mysql_ssl_set()’s parameters.
主要是這邊的說明- MySQL :: MySQL 5.7 C API Developer Guide :: 5.4.75 mysql_ssl_set()
- Working with AWS RDS proxy endpoint on read replica with SQLAlchemy | by James Li | Medium