1
1

AWS System Manager Session Managerでローカル環境とRDSを接続したい

Last updated at Posted at 2024-09-14

はじめに

Table PlusでAmazon RDSのデータを確認するために、EICE接続を使用してローカル環境とAmazon RDSを接続したのですが、Prisma CloudのアラートInstances exposed to network trafficfrom the internetが出てしまいました。
セキュリティグループのインバウンドルールを変更してもアラートが再発したため、SSM接続に変更。
EICE接続とSSM接続の違いについてまとめていきます。

接続条件

ローカルではTable Plus、RDSはPostgreSQLを使用しています。
【ポート設定】
Local Port:5433(任意) Remote Port:5432とします。

image.png

EICE接続

まずは、現状使用しているEICE接続です。
EC2 Instance Connect Endpoint (EICE)は、パブリックIPアドレスを使用せずに、EC2インスタンスへのSSH接続とRDP接続を行える

特徴
セキュリティグループによるポートの開放が必要

image.png

接続手順

ターミナルで

  1. AWS access portalのアクセスキーを入力
  2. 下記コマンドを入力
ssh -i ~/.ssh/<作成したキーペア>.pem \
-L 5433:<RDS DB名>.xxxxxx.ap-northeast-1.rds.amazonaws.com:5432 \
ec2-user@i-xxxxxxxxxxx \
-o ProxyCommand='aws ec2-instance-connect open-tunnel --instance-id i-xxxxxxxxxxx'

SSM接続

次にSSM接続です。
Session ManagerはAWS Systems Manager(SSM)の機能の一つで、使用する際はEICE接続で使用していたEC2にアタッチしているセキュリティグループのインバウンドルールは全て削除します

特徴

  • セキュリティグループによるポートの開放が不要
  • アクティビティのログが保存可能

image.png

接続手順

ターミナルで

  1. AWS access portalのアクセスキーを入力
  2. 下記コマンドを入力
aws ssm start-session \--target i-xxxxxxxxxxx \
    --document-name AWS-StartPortForwardingSessionToRemoteHost \
    --parameters '{"host":["<RDS名>.xxxxxx.ap-northeast-1.rds.amazonaws.com"],"portNumber":["5432"], "localPortNumber":["5433"]}'

最後に

ユーザー様に提供できる機能の追加にエクスタシーを感じるけど、セキュリティ面の強化にもエクスタシーを感じていけるように勉強していこう!

参考記事

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1