Open7
EC2 Instance Connect Endpoint を試す
![koki-algebra](https://res.cloudinary.com/zenn/image/fetch/s--4vbo7rbn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_70/https://storage.googleapis.com/zenn-user-upload/avatar/58922af5f8.jpeg)
サンプル
![koki-algebra](https://res.cloudinary.com/zenn/image/fetch/s--4vbo7rbn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_70/https://storage.googleapis.com/zenn-user-upload/avatar/58922af5f8.jpeg)
公式ドキュメント
![koki-algebra](https://res.cloudinary.com/zenn/image/fetch/s--4vbo7rbn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_70/https://storage.googleapis.com/zenn-user-upload/avatar/58922af5f8.jpeg)
基本的にはサブネットに EC2 Instance Connect Endpoint をアタッチするだけで使えるっぽい。
セキュリティグループとか IAM ポリシーは正しく設定しよう。
以下のコマンドで接続可能。
aws ec2-instance-connect ssh --instance-id <instance-id> --connection-type eice
![koki-algebra](https://res.cloudinary.com/zenn/image/fetch/s--4vbo7rbn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_70/https://storage.googleapis.com/zenn-user-upload/avatar/58922af5f8.jpeg)
SSH Key の管理はいらないし、IAM だけでコントロールできるのは素晴らしい。
![koki-algebra](https://res.cloudinary.com/zenn/image/fetch/s--4vbo7rbn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_70/https://storage.googleapis.com/zenn-user-upload/avatar/58922af5f8.jpeg)
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
![koki-algebra](https://res.cloudinary.com/zenn/image/fetch/s--4vbo7rbn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_70/https://storage.googleapis.com/zenn-user-upload/avatar/58922af5f8.jpeg)
MySQL の場合はプロトコルを明示する必要があるっぽい。
mysql --protocol TCP --host localhost --user <username> --password