LoginSignup
1
0

[祝!]EC2 Instance Connect Endpoint経由でRDS(3389)に接続できた話

Last updated at Posted at 2023-06-29

背景

Twitter でプロフィールエンジニアリング中の @___nix___ です。

さて、

EC2 Instance Connect Endpoint経由でRDSに接続してみた

で一躍有名になった 「EC2 Instance Connect Endpoint経由でRDSに接続」 のお話でしたが、数日後には利用可能ポートが制限されてしまいました。

awscli.customizations.ec2instanceconnect.websocket - ERROR - {"ErrorCode":"InvalidParameter","Message":"The specified RemotePort is not valid. Specify either 22 or 3389 as the RemotePort and retry your request."}

「AWS はなんてことをしてくれたんだ!」

と界隈では落胆の空気が流れる一方で...

「RDSのポートを 3389 にすればRDSに接続できるんじゃね?」

で、早速やってみた!

構築手順

RDS と VPCエンドポイント用に SecurityGroup を準備

ここは省略しますが、クラメソさんの記事を参考にしてください。

RDS を構築

もちろん 3389 ポートで。

VPCエンドポイントも構築

あと少しです。

接続

RDS のプライベートIPを調べる

host database-1.cluster-xxxxxxxx.ap-northeast-1.rds.amazonaws.com
172.31.0.118

VPCエンドポイントのIDを調べる

これはAWSマネージドコンソールから取得してください。

open-tunnel を実行

3389 を 13389 にポートフォアディングします。

/usr/local/bin/aws ec2-instance-connect open-tunnel --instance-connect-endpoint-id eice-xxxxxxxxxxxx --private-ip-address 172.31.0.118 --local-port 13389 --remote-port 3389 &

以下のメッセージが出ればOKです。

Listening for connections on port 13389.

ドキドキの瞬間

mysql -u admin -h 127.0.0.1 -p -P 13389
Enter password:
[3] Accepted new tcp connection, opening websocket tunnel.
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 229
Server version: 5.7.12 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [(none)]>

キタ━━━━(゚∀゚)━━━━!!

編集後記

多分、最速記事。
だと思う...。

AWSさん的に都合の良い記事なのか?
ごめんなさいね。

悪い使い方はせずに正しく使おう!

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