How do I troubleshoot an AWS CloudFormation stack that's in DELETE_FAILED status?

Last updated: 2019-06-04

My AWS CloudFormation stack is stuck in the DELETE_FAILED status. How can I delete my stack?

Short Description

Your stack could be stuck in the DELETE_FAILED status for the following reasons:

  • A stack resource has a dependent object or other dependencies that can't be deleted.
  • A security token included in the Delete request is invalid, or the role is invalid or can't be assumed.
  • An export value from one stack (StackA) can't be deleted because it's being used by another stack (StackB) or stacks.
  • A custom resource failed to stabilize in the expected amount of time.

Resolution

Delete a stack with a dependent object or other dependencies that cannot be deleted

Dependency issues usually occur when you make an out-of-band change. For example, if a security group that's part of your stack is attached to an elastic network interface (ENI) that's not part of your stack, then your stack will fail. The stack fails because the security group resource can't be deleted. To delete the stack, you must retain that resource, and then complete the following steps:

1.    Open the AWS CloudFormation console.

2.    Choose the stack that's stuck in the DELETE_FAILED status.

3.    Choose Actions, and then choose Delete Stack.

4.    In the pop-up window that lists your resources to retain, choose the resource that's stuck in DELETE_FAILED status, and then choose Delete.

5.    Choose Actions, and then choose Delete Stack.

The status of your stack changes to DELETE_COMPLETE.

Note: To avoid unnecessary charges, you must manually delete the resources that are retained when the stack is deleted.

Delete a stack with an invalid security token or invalid role

You might see an error if you try to delete a stack that was created using a service role that doesn't exist. The error could be similar to the following: "The security token included in the request is invalid. Role is invalid or cannot be assumed." To resolve this error, complete the following steps:

1.    Open the AWS CloudFormation console.

2.    Choose the stack that's stuck in the DELETE_FAILED status, and then choose the Overview tab.

3.    For IAM role, identify the name of the invalid AWS Identity and Access Management (IAM) role.

4.    Create an IAM role using the same name as the IAM role in step 3.

Important: Verify that your IAM role has the right permissions to delete the stack.

5.    In the AWS CloudFormation console, delete the stack that's stuck in the DELETE_FAILED status.

The status of your stack changes to DELETE_COMPLETE.

Delete a stack with an export value that cannot be deleted

If you try to delete a stack with an export value that's used by another stack, the stack deletion fails. You might see an error similar to the following: "Export export_value cannot be deleted as it is in use by StackA and StackB." To resolve this error, complete the following steps:

1.    Open the AWS CloudFormation console.

2.    Choose StackA, and then choose the Template tab.

3.    In your AWS CloudFormation template, replace Fn::ImportValue with the actual export value. For example, if the export name is Snstopicname and the export value is awssnstopic, then replace Fn::ImportValue : Snstopicname with awssnstopic as in the following example.

Template with the original export name:

AWSTemplateFormatVersion: '2010-09-09'
Resources:
  MySNSTopic:
    Type: 'AWS::SNS::Topic'
    Properties:
      TopicName: 
          'Fn::ImportValue': Snstopicname

Template with the updated export value:

AWSTemplateFormatVersion: '2010-09-09'
Resources:
  MySNSTopic:
    Type: 'AWS::SNS::Topic'
    Properties:
      TopicName: awssnstopic

4.    To remove all the references for Fn::Import, update the stack using the preceding template that includes the updated export value.

5.    Repeat step 2 and step 3 for StackB.

6.    After the updates are complete for StackA and StackB, delete the stack in DELETE_FAILED status.

The status of your stack changes from the DELETE_FAILED status to the DELETE_COMPLETE status.

Delete a stack for a custom resource that failed to stabilize

For instructions to delete a stack for a custom resource that failed to stabilize in the expected amount of time, see How do I troubleshoot an AWS Lambda-backed custom resource that's stuck in DELETE_FAILED status or DELETE_IN_PROGRESS status with AWS CloudFormation?


Did this article help you?

Anything we could improve?


Need more help?