How do I update an AWS CloudFormation stack that's failing because of a resource that I manually deleted?
Last updated: 2020-03-18
I manually deleted a resource that was created by one of my AWS CloudFormation stacks, and now my stack won't update. How can I update my stack?
If you delete a resource from an AWS CloudFormation stack, then you must remove the resource from your AWS CloudFormation template. Otherwise, your stack fails to update, and you get an error message.
Update a resource that you created manually
You can get your stack to update by replacing a manually created resource that you deleted with a new resource. The new resource, however, must have the same name as the deleted resource.
For example, because AWS Identity and Access Management (IAM) roles are tracked by name, changing the name of a resource can affect how roles are handled. If you accidentally delete an IAM role, then you can manually recreate that role with the same name.
To update an IAM role or other resource that you created manually, complete the following steps:
- Open the AWS CloudFormation console.
- Select your stack, and then choose the Resources view.
- In the Physical ID column, find the Physical ID of the IAM role that you want to replace with a new IAM role that you're creating.
Note: The Physical ID is the name of the resource.
- Create a new IAM role, and then give the new role the same Physical ID that you found in step 3.
- Update your stack.
Note: For more information, see Modifying a Stack Template.
Update a resource with a unique ID
You can't manually recreate a resource, such as a route table, with a unique ID. Instead, you must remove the resource and any references to that resource from your AWS CloudFormation template.
To allow AWS CloudFormation to recreate a route table or other resource with a unique ID, complete the following steps:
- In your AWS CloudFormation template, remove the route table and any references to the route table.
- Update the stack that doesn't contain your route table.
- Add the route table and any additional resources or references that you require back to your AWS CloudFormation template.
Note: AWS CloudFormation recreates the deleted resource.
- Update your stack again.