简体   繁体   中英

AWS CDK Update an existing DynamoDB Table

When CDK project tries to update an existing DynamoDB table, it throws a CloudFormation error "Cannot update a stack when a custom-named resource requires replacing". I have to name the talbe to another name, eg from my-table to my-table-2 to deploy the changes to the table. And then change the table name back to my-table and deploy one more time.

Is there anyway to avoid this?

This happens because when an update requires a resource to be replaced, CloudFormation creates the new version and deletes the old one afterwards. Because two resources with the same physical name cannot exist, this fails.

The solution is to not specify the table name and let CloudFormation generate the name itself. This way, if an update requires replacement, CloudFormation will generate a new name for the resource.

This is explicitly advised in the CDK documentation :

Assigning physical names to resources has some disadvantages in AWS CloudFormation. Most importantly, any changes to deployed resources that require a resource replacement, such as changes to a resource's properties that are immutable after creation, will fail if a resource has a physical name assigned. If you end up in that state, the only solution is to delete the AWS CloudFormation stack, then deploy the AWS CDK app again.

Related CloudFormation docs .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM