When I try to update an AWS CloudFormation stack, I get an error message similar to the following: "CloudFormation cannot update a stack when a custom-named resource requires replacing. Rename 'MyResource###' and update the stack again."
Short description
This error occurs when a stack update tries to replace resources that have properties with custom names. CloudFormation doesn't replace a resource that has a custom name unless that custom name is changed to a different name. To prevent a stack failure, before you update a stack, be sure that you change any resources with custom names to use different names.
The resolution for this error assumes the following:
- You're updating an existing stack and not creating a new stack.
- You're changing the names of existing custom-named resources and not creating new custom-named resources.
Resolution
-
In a code editor, open the CloudFormation template for the stack that you want to update.
-
Replace the names or values of any resource properties that have custom names to use different names.
Note: In the following example, the DBInstanceIdentifier property of the MyRDS resource is set to the custom name PRODdb. The CloudFormation stack can't be updated until the name PRODdb is changed to a different name, such as PRODdb1. Or, omit the DBInstanceIdentifier property from your template so that CloudFormation generates a unique physical ID to use for the DB instance.
"MyRDS": { "Type": "AWS::RDS::DBInstance",
"Properties": {
"DBInstanceClass": "db.m3.medium",
"Engine": "MySQL",
"DBInstanceIdentifier": "PRODdb",
"AllocatedStorage": "10",
"AutoMinorVersionUpgrade": "true",
"BackupRetentionPeriod": "0",
. . .
. . .
}
}
Important: When you rename a custom-named resource, CloudFormation replaces that resource. For more information, see Name type. Replacement of certain resources can cause data loss without proper backup. For more information, see Replacement.
-
Save the changes to your CloudFormation template, and then use the template to update your stack.
Related information
Managing AWS resources as a single unit with CloudFormation stacks
Understand update behaviors of stack resources
AWS resource and property types reference