2
3

More than 3 years have passed since last update.

【初心者】Amazon RDS 証明書の更新と影響確認

Posted at

目的

  • 2020/2/5 までに、RDSの証明書更新が推奨されている。作業手順及び影響(どれくらい止まるのか?)を実機で確認する。

やったこと

  • 検証用のRDS(MySQL 5.7, シングル構成)を立てる。
  • RDSに対して1秒間隔でINSERTを実行している状態で、証明書の変更処理を行い、応答不可となる時間を確認する。

構成図

構成図.png

作業手順

事前準備(1秒間隔でのINSERT)

  • RDS内に適当なDatabase及びTableを作成する。
mysql> create database mksambadb;
mysql> use mksambadb;
mysql> create table mksambadb.mytable(id int, stamp varchar(30)); 
insert-timestamp.py
import MySQLdb  # mysqlclient ドライバを利用する
import datetime
import time

num = 0
errornum = 0

while True:
    try:
        # RDSに接続
        connection = MySQLdb.connect(
            host='database-1.xxxxxxxxxxxx.ap-northeast-1.rds.amazonaws.com',
            user='xxxxxx',
            passwd='xxxxxx',
            db='mksambadb')
        cursor = connection.cursor()

        # 現在時刻を取得
        dt_now = datetime.datetime.now()

        # 連番及び現在時刻をINSERTして、COMMIT後にコネクションを切断する
        cursor.execute("INSERT INTO mksambadb.mytable VALUES (%s, %s)", (num, dt_now))
        connection.commit()
        connection.close()
        print(num,dt_now)

        # 1秒待って最大500回繰り返し
        time.sleep(1)
        num += 1
        if num >= 500:
            break

    except MySQLdb.Error as e:
        # MySQLとの接続エラー時、1秒待って再接続、を最大100回行う
        errornum += 1
        print('MySQLdb.Error: ', e)
        time.sleep(1)
        if errornum >= 100:
            break

証明書更新

  • RDSの画面で、左ペインメニューから「Certficate update」を選択すると、証明書更新が必要なデータベースが表示される。(今回は「database-1」)

cert01a.png

  • 対象のデータベース「database-1」を選択し、右上の「変更」を押す。

cert02a.png

  • 変更箇所の確認画面にて、「認証機関」を「rds-ca-2015」から「rds-ca-2019」に変更し、「次へ」を押す。

cert03.png

  • 「変更のスケジュール」にて「すぐに適用」を選択し、「DBインスタンスの変更」を押し、設定変更を実行する。

cert04a.png

結果確認

  • マネージメントコンソールでのログ確認
    • 10:05:27 に shutdown, 10:05:38 に restarted とのログあり。

cert05.png

  • INSERTの応答確認
    • マネージメントコンソールで設定変更のボタンを押してから、約47秒経過後、1秒間隔のINSERTが4回失敗した(4~5秒程度の断)。
$ python3 insert-timestamp.py
------ 42回実行 ------
43 2019-12-26 10:05:19.410014
44 2019-12-26 10:05:20.461018
45 2019-12-26 10:05:21.513252
46 2019-12-26 10:05:22.562890
47 2019-12-26 10:05:23.613058
MySQLdb.Error:  (2003, "Can't connect to MySQL server on 'database-1.xxxxxxxxxxxx.ap-northeast-1.rds.amazonaws.com' (111)")
MySQLdb.Error:  (2003, "Can't connect to MySQL server on 'database-1.xxxxxxxxxxxx.ap-northeast-1.rds.amazonaws.com' (111)")
MySQLdb.Error:  (2003, "Can't connect to MySQL server on 'database-1.xxxxxxxxxxxx.ap-northeast-1.rds.amazonaws.com' (111)")
MySQLdb.Error:  (2003, "Can't connect to MySQL server on 'database-1.xxxxxxxxxxxx.ap-northeast-1.rds.amazonaws.com' (111)")
48 2019-12-26 10:05:28.734436
49 2019-12-26 10:05:29.826749
50 2019-12-26 10:05:30.877319
51 2019-12-26 10:05:31.927263
52 2019-12-26 10:05:32.977715

所感

  • 本検証構成においては、断は短時間であることを確認できた。
  • 証明書の存在を普段あまり意識していないため、勉強になった。
2
3
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
2
3