2022-10-04
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

Read More

2022-08-17
rds-ssh-tunnel

ssh tunnel 設定的參考

  • ssh -i <identity_file> -f -l <bastion-host-username> -L <local-port-you-connect-to>:<rds-endpoint>:<rds:listening-port> <bastion-host-public-ip> -v
  • Example Command
    • ssh -i "private_key.pem" -f -l ec2-user -L 5432:172.31.39.62:5432 3.133.141.189 -v

Reference

Read More