Open9

aws cliを使ったスナップショットからのDBインスタンス作成と削除

Hid3Hid3

インスタンス作成・起動・停止があるとして、既に作成されているインスタンスにスナップショットを上書き?して起動できる?

Hid3Hid3

スナップショットからの復元は新しいインスタンスが立ち上がる。

Hid3Hid3

Fargateタスク内でスクリプトを実行。
そのスクリプトないでaws cliからインスタンスの作成と削除をします。

再実行とかでインスタンスが大量に作られないように。
本番DBミスって消さないようにね。
削除保護ついてるけど、APIからの場合効かないとかないよね?確認。

Hid3Hid3

rds関連の必要なポリシー
・対象DBのスナップショット読み込み
・インスタンス作成
・対象DBインスタンスの削除

"Action": [
"rds:DescribeDBSnapshots",
"rds:RestoreDBInstanceFromDBSnapshot"
],

Hid3Hid3

aws cliでのインスタンス作成
https://dev.classmethod.jp/articles/restoring-from-db-snapshot-with-awscli-ja/

snapshotの検索は?
pythonだけど
https://dev.classmethod.jp/articles/aws-lambda-rds-restore/

 identifier=`aws rds describe-db-snapshots \
    --db-instance-identifier $db_instance \
    --snapshot-type $snapshot_type \
    --query 'reverse(sort_by(DBSnapshots,&InstanceCreateTime))[0].DBSnapshotIdentifier'`
  echo $identifier | sed 's/"//g'

ダブルクオーテーション自体も文字列の一部となってエラー起きたので。