Aurora PostgreSQL に RDS Proxy 経由で IAM 認証で接続する手順。
前提
$ sudo yum -y install postgresql
手順
同一アカウントから
$ export RDSHOST=aurora-postgres-117.proxy-************.ap-northeast-1.rds.amazonaws.com $ export PGPASSWORD="$(aws rds generate-db-auth-token --hostname $RDSHOST --port 5432 --region ap-northeast-1 --username awsuser)" $ psql -h $RDSHOST -p 5432 -d postgres -U awsuser
クロスアカウントアクセス(VPCピアリング接続、共有VPCなど)
$ cat .aws/config [default] region = ap-northeast-1 [profile instancecrossaccount] region = ap-northeast-1 role_arn = arn:aws:iam::234567890123:role/EC2SwitchRole credential_source = Ec2InstanceMetadata sts_regional_endpoints=regional $ export RDSHOST=aurora-postgres-117.proxy-************.ap-northeast-1.rds.amazonaws.com $ export PGPASSWORD="$(aws rds generate-db-auth-token --hostname $RDSHOST --port 5432 --region ap-northeast-1 --username awsuser --profile instancecrossaccount)" $ psql -h $RDSHOST -p 5432 -d postgres -U awsuser