Open7
EC2 Instance Connect Endpoint を試す

サンプル

公式ドキュメント

基本的にはサブネットに EC2 Instance Connect Endpoint をアタッチするだけで使えるっぽい。
セキュリティグループとか IAM ポリシーは正しく設定しよう。
以下のコマンドで接続可能。
aws ec2-instance-connect ssh --instance-id <instance-id> --connection-type eice

SSH Key の管理はいらないし、IAM だけでコントロールできるのは素晴らしい。

Aurora への接続
EC2 Instance Connect Endpoint でポートフォワーディングするには --local-forwarding
というオプションを使えば良い。
aws ec2-instance-connect ssh --instance-id <instance-id> --connection-type eice --local-forwarding 5432:<RDS endpoint>:5432
以下のコマンドでポートフォワーディングされていることを確かめる。
sudo lsof -P -i:5432
ローカル (Mac) から PostgreSQL Client で Aurora に接続する。
psql --host localhost --username <username> --dbname <dbname> --password

MySQL の場合はプロトコルを明示する必要があるっぽい。
mysql --protocol TCP --host localhost --user <username> --password