0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【AWS】CloudFormation cannot update a stack when a custom-named resource requires replacingというエラーが出た場合

Posted at

概要

AWS CDKでRDSインスタンスを作成する際に、

db_name="sample_db"

の値を変更したら以下のエラーになった。

CloudFormation cannot update a stack when a custom-named resource requires replacing. Rename sample-mysql and update the stack again.

解決方法

db_instance_identifierの値を新しくすることで解決します。

なぜかというと、db_nameなど一部のプロパティを変更すると、リソースの置き換え(Replacement)が必要になるため。

db_instance_identifier(RDSインスタンス名)を明示的に指定している場合、
既存のインスタンスと同じ名前で新しいリソースを作成できないため、
CloudFormationは「リネームして再実行してください」というエラーを出している、ということです。

以下のように新しい値にすることで解決しました。

        rds_instance = rds.CfnDBInstance(
            self, "Sample-RDS",
            db_instance_identifier="sample-mysql-new", # ここを新しい値に
            db_instance_class="db.t3.micro",
            db_name="sample_db",
            engine="mysql",
            engine_version="8.0.41",
            allocated_storage="20",
            max_allocated_storage=100,
            db_subnet_group_name=rds_subnet_group.ref,
            vpc_security_groups=[rds_security_group.ref],
            master_username=rds_secret.secret_value_from_json("username").unsafe_unwrap(),
            master_user_password=rds_secret.secret_value_from_json("password").unsafe_unwrap(),
            publicly_accessible=False,
        )

ただし、これは検証期間中にのみ実行してよいものです。
既存インスタンスが削除され新規作成となるとデータも消失するので要注意。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?