1
0

【AWS】SSMで管理しているEC2にportforwardしてローカルからRDSに接続する

Last updated at Posted at 2024-07-09

概要

下図の通りEC2 にSSM agentをinstallしてそこから繋ぐことが出来るRDSにローカルアクセスします。

前提

  • EC2 に SSM agentをinstall 済
  • EC2 から RDSにアクセス出来るVPC設定
  • RDS は パスワードで管理
  • ローカルではGUIツールを使用(この記事ではHeidiSQL)

手順

  1. EC2のinstance-IDを確認する

  2. portforwardを実施

windows

aws ssm start-session ^
--target i-xxxxx ^
--document-name AWS-StartPortForwardingSessionToRemoteHost ^
--parameters "{\"portNumber\":[\"3306\"],\"localPortNumber\":[\"3306\"],\"host\":[\"rds-dev.xxxxx.ap-northeast-1.rds.amazonaws.com\"]}" ^
--profile iamuser-xxxxx

mac

aws ssm start-session \
--target i-xxxxx \
--document-name AWS-StartPortForwardingSessionToRemoteHost \
--parameters '{"portNumber":["3306"],"localPortNumber":["3306"],"host":["rds-dev.xxxxx.ap-northeast-1.rds.amazonaws.com"]}' \
--profile iamuser-xxxxx
  1. RDSにアクセス

以下の値を入力し、「開く」

項目
ネットワーク種別 MariaDB or MySQL(TCP/IP)
ホスト名/IP localhost
ユーザー ${user名}
パスワード ${パスワード}
ポート 3306

参考

1
0
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
0