2020年11月29日日曜日

AWS RDS/Auroraを停止状態から削除する

停止状態からAWSのDBを削除できるか

RDS DBを止めた状態(stopped)から消す、をいうことを試していたときのメモ。

RDSを消す

RDSは停止状態から消せます。
ちなみにDeletion Policyも、停止したままで変更できます。

Auroraを消す


Auroraは停止状態では消すことができません。
Startしてからでないと消せません。

こういうエラーが出ます。(database-2というDB名)

$ aws rds delete-db-instance --db-instance-identifier database-2-instance-1

An error occurred (InvalidDBClusterStateFault) when calling the DeleteDBInstance operation: Db cluster database-2 is in stopped state


Auroraを消すときの手順

クラスター内のインスタンスを全て消してからクラスターを消します。 

https://aws.amazon.com/premiumsupport/knowledge-center/rds-error-delete-aurora-cluster/


最後の1つのインスタンスを消すと、同時にクラスターも削除されます。
https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/USER_DeleteInstance.html


クラスターでDeletion ProtectionがEnableとなっていても、中のインスタンスは削除できます。ただし、最後の1つのインスタンスを消しても、クラスターが残っていて、データも残っている扱いになるようです。再開するにはインスタンスを追加します。
Aurora clusters with a single DB instance
If you try to delete the last DB instance in your Aurora cluster, the behavior depends on the method you use. You can delete the last DB instance using the AWS Management Console. Doing so also deletes the DB cluster. You can also delete the last DB instance through the AWS CLI or API, even if the DB cluster has deletion protection enabled. In this case, the DB cluster itself still exists and your data is preserved. You can access the data again by attaching a new DB instance to the cluster.

コンソールで消せなくなるとき

最後にRegionalだけを残したら、Consoleでは消せなくなりました。CLIでこのようにして消しました。

$ aws rds delete-db-cluster  --db-cluster-identifier database-2 --skip-final-snapshot


余談

 DBは停止していても7日で自動で動き始めるので注意が必要です。それに関しては対策が公式blogで紹介されています。

https://aws.amazon.com/blogs/architecture/field-notes-stopping-an-automatically-started-database-instance-with-amazon-rds/

0 件のコメント:

コメントを投稿