既存DBの暗号化

(1)RDS (MySQL)


-- 1. インスタンス作成

aws rds create-db-instance \
--db-instance-identifier mysql01 \
--allocated-storage 20 \
--db-instance-class db.t3.micro \
--engine mysql \
--master-username root \
--master-user-password 'password' \
--no-multi-az \
--engine-version 8.0.25 \
--storage-type gp2 \
--no-publicly-accessible \
--no-enable-performance-insights \
--no-auto-minor-version-upgrade

 

-- 2. スナップショット作成

aws rds create-db-snapshot \
--db-snapshot-identifier snap01 \
--db-instance-identifier mysql01


-- 3. 既存インスタンス削除
aws rds delete-db-instance \
--db-instance-identifier mysql01 \
--skip-final-snapshot


-- 4. スナップショットの暗号化
★RDSの場合は必要

aws rds copy-db-snapshot \
--source-db-snapshot-identifier snap01 \
--target-db-snapshot-identifier snap02 \
--kms-key-id arn:aws:kms:ap-northeast-1:999999999999:key/11111111-2222-3333-4444-555555555555


-- 5. 暗号化スナップショットからの復元

aws rds restore-db-instance-from-db-snapshot \
--db-instance-identifier mysql01 \
--db-snapshot-identifier snap02


(2)Aurora MySQL

-- 1. クラスタ作成

aws rds create-db-cluster \
--db-cluster-identifier cluster01 \
--engine aurora-mysql \
--engine-version 5.7.mysql_aurora.2.10.0 \
--master-username root \
--master-user-password 'password'

aws rds create-db-instance \
--db-instance-identifier cluster01-instance01 \
--db-cluster-identifier cluster01 \
--db-instance-class db.t3.small \
--engine aurora-mysql \
--no-auto-minor-version-upgrade

-- 2. スナップショット作成

aws rds create-db-cluster-snapshot \
--db-cluster-identifier cluster01 \
--db-cluster-snapshot-identifier snap01

-- 3. 既存クラスタ削除

aws rds delete-db-instance \
--db-instance-identifier cluster01-instance01 \
--skip-final-snapshot

aws rds delete-db-cluster \
--db-cluster-identifier cluster01 \
--skip-final-snapshot

-- 4. スナップショットからの復元(kms-key-idを指定する)

aws rds restore-db-cluster-from-snapshot \
--db-cluster-identifier cluster01 \
--snapshot-identifier snap01 \
--engine aurora-mysql \
--kms-key-id arn:aws:kms:ap-northeast-1:999999999999:key/11111111-2222-3333-4444-555555555555


aws rds create-db-instance \
--db-cluster-identifier cluster01 \
--db-instance-identifier cluster01-instance01 \
--db-instance-class db.t3.small \
--engine aurora-mysql

 

(3)Redshift

-- 1. クラスターの作成

aws redshift create-cluster \
--db-name test \
--cluster-identifier redshift01 \
--cluster-type single-node \
--node-type dc2.large \
--master-username test \
--master-user-password 'password' \
--no-allow-version-upgrade \
--no-publicly-accessible

aws redshift describe-clusters --cluster-identifier redshift01

-- 2. クラスターの暗号化
移行オペレーション中、クラスターは読み取り専用モードで閲覧可能になり、クラスターのステータスは [サイズ変更] と表示されます。

aws redshift modify-cluster \
--cluster-identifier redshift01 \
--encrypted

 

(4)DocumentDB

-- 1. クラスタ作成

aws docdb create-db-cluster \
--db-cluster-identifier cluster01 \
--engine docdb \
--engine-version 4.0.0 \
--port 27017 \
--master-username test \
--master-user-password 'password' \
--no-storage-encrypted \
--no-deletion-protection


aws docdb create-db-instance \
--db-instance-identifier instance01 \
--db-instance-class db.t3.medium \
--engine docdb \
--no-auto-minor-version-upgrade \
--db-cluster-identifier cluster01

-- 2. スナップショット作成

aws docdb create-db-cluster-snapshot \
--db-cluster-identifier cluster01 \
--db-cluster-snapshot-identifier snap01


-- 3. 既存クラスタ削除

aws docdb delete-db-instance \
--db-instance-identifier instance01

aws docdb delete-db-cluster \
--db-cluster-identifier cluster01 \
--skip-final-snapshot 

-- 4. スナップショットからの復元(kms-key-idを指定する)

aws docdb restore-db-cluster-from-snapshot \
--db-cluster-identifier cluster01 \
--snapshot-identifier snap01 \
--engine docdb \
--kms-key-id arn:aws:kms:ap-northeast-1:999999999999:key/11111111-2222-3333-4444-555555555555


aws docdb create-db-instance \
--db-instance-identifier instance01 \
--db-instance-class db.t3.medium \
--engine docdb \
--no-auto-minor-version-upgrade \
--db-cluster-identifier cluster01


(5)Neptune

-- 1. クラスタ作成

aws neptune create-db-cluster \
--db-cluster-identifier cluster01 \
--engine neptune \
--engine-version 1.0.5.0 \
--port 8182 \
--no-storage-encrypted \
--no-deletion-protection

aws neptune create-db-instance \
--db-cluster-identifier cluster01 \
--engine neptune \
--db-instance-identifier instance01 \
--db-instance-class db.t3.medium \
--no-multi-az \
--no-auto-minor-version-upgrade

-- 2. スナップショット作成

aws neptune create-db-cluster-snapshot \
--db-cluster-identifier cluster01 \
--db-cluster-snapshot-identifier snap01


-- 3. 既存クラスタ削除

aws neptune delete-db-instance --db-instance-identifier instance01 --skip-final-snapshot
aws neptune delete-db-cluster --db-cluster-identifier cluster01 --skip-final-snapshot 


-- 4. スナップショットからの復元(kms-key-idを指定する)

aws neptune restore-db-cluster-from-snapshot \
--db-cluster-identifier cluster01 \
--snapshot-identifier snap01 \
--engine neptune \
--kms-key-id arn:aws:kms:ap-northeast-1:999999999999:key/11111111-2222-3333-4444-555555555555


aws neptune create-db-instance \
--db-cluster-identifier cluster01 \
--engine neptune \
--db-instance-identifier instance01 \
--db-instance-class db.t3.medium \
--no-multi-az \
--no-auto-minor-version-upgrade


(6)ElastiCache Redis

-- 1. テスト用クラスタ作成 (クラスターモードが無効(レプリカあり)のクラスター)
aws elasticache create-replication-group \
--replication-group-id redis01 \
--replication-group-description "redis01" \
--num-cache-clusters 2 \
--cache-node-type cache.t3.micro \
--cache-parameter-group default.redis6.x \
--engine redis \
--engine-version 6.x \
--multi-az-enabled

aws elasticache describe-cache-clusters --cache-cluster-id redis01-001
aws elasticache describe-cache-clusters --cache-cluster-id redis01-001 --show-cache-node-info

-- 2. バックアップ作成

aws elasticache create-snapshot \
--cache-cluster-id redis01-001 \
--snapshot-name snap01

★コンソールでは暗号化されているように見えるが、実はされていない


-- 3. 既存クラスタ削除

aws elasticache delete-replication-group \
--replication-group-id redis01 \
--no-retain-primary-cluster


-- 4. バックアップからの復元(保管時暗号化オプション指定)
aws elasticache create-replication-group \
--replication-group-id redis01 \
--replication-group-description "redis01" \
--num-cache-clusters 2 \
--cache-node-type cache.t3.micro \
--cache-parameter-group default.redis6.x \
--engine redis \
--engine-version 6.x \
--multi-az-enabled \
--snapshot-name snap01 \
--at-rest-encryption-enabled