LoginSignup
0
0
はじめての記事投稿

EC2 instance connect で RDS に接続してみる

Last updated at Posted at 2023-07-01

EC2 のセットアップ

まずは EC2 インスタンスのセットアップから始めます。

やったこと

コンソール上で選択した項目などをリストにしています。

  • EC2インスタンス作成・起動
    • amazon linux 2023 を選択しサイズなどもろもろ設定
    • サブネットをパブリックに
    • パブリックIP有効化
    • 適宜 VPC 選択
  • RDS の SG に EC2インスタンスのプライベートIPを設定

psql のインストール

このとき、インスタンスが Amazon Linux 2023 であることを失念しており少し手惑いました。

sudo dnf search postgresql
sudo dnf install -y postgresql15-server
which psql
/usr/bin/psql

インストールできました。

psql "host=hogehoge.cluster-xxxxxxxxxx.ap-northeast-1.rds.amazonaws.com user=postgres dbname=fugafuga port=5432"

Password for user postgres: 
psql (15.0, server 13.6)
SSL connection (protocol: TLSv1.2, cipher: DHE-RSA-AES128-SHA, compression: off)
Type "help" for help.

fugafuga=> 

RDS の PostgreSQL にログインできました。
(サーバーが13.6なのは意図的です)

fugafuga=> \dt;
                 List of relations
 Schema |          Name          | Type  |  Owner   
--------+------------------------+-------+----------
 public | failed_jobs            | table | postgres
 public | folder_item_orders     | table | postgres
 public | migrations             | table | postgres
 public | password_resets        | table | postgres
 public | personal_access_tokens | table | postgres
 public | users                  | table | postgres
(11 rows)

テーブル一覧も確認することができました。

いろいろやり方はあるとは思いますが EC2 Instance Connect を利用することで比較的手間なく RDS に接続することができたと思います。

以上です。

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