How do I update a CloudFormation stack that's failing because of a resource that I manually deleted?

3 minute read
0

I manually deleted a resource that was created by one of my AWS CloudFormation stacks, and now my stack won't update.

Short description

If you delete a resource that was created by a CloudFormation stack, then your stack fails to update, and you get an error message.

Choose one of the following resolutions based on your resource type:

  • Update a resource with a unique name
  • Update a resource with a unique ID

Resolution

Update a resource with a unique name

If the deleted resource supports a unique name, you can get your stack to update by manually creating the resource. The new resource, however, must have the same name as the deleted resource. For example, you can impact how CloudFormation handles a resource when you change a resource name. This is because AWS Identity and Access Management (IAM) roles are tracked by name. If you accidentally delete an IAM role, you can manually recreate that role with the same name.

To update an IAM role or any other resource with a unique name, complete the following steps:

  1. Open the AWS CloudFormation console.
  2. Select your stack, and then choose the Resources view.
  3. In the Physical ID column, find the Physical ID of the IAM role that you want to replace with your new IAM role.
    Note: The Physical ID is the name of the resource.
  4. Create a new IAM role, and then give the new role the same Physical ID that you found in step 3.
  5. 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 CloudFormation template.

Note: The following resolution also works for resources that don't support a unique name or a unique ID. For example, a record set in a hosted zone.

To allow CloudFormation to recreate a route table or any other resource with a unique ID, complete the following steps:

  1. In your CloudFormation template, remove the route table and any references to it.
  2. Update the stack.
    Note: CloudFormation tries to delete the route table. Because the resource has already been deleted, CloudFormation considers the deletion a successful operation.
  3. Add the route table and any additional resources or references that you require back to your CloudFormation template.
  4. Update your stack again.
    Note: CloudFormation recreates the deleted resource.

Related information

Troubleshooting AWS CloudFormation

AWS OFFICIAL
AWS OFFICIALUpdated 3 years ago