Deleting a stack
To delete a stack, you run the aws cloudformation delete-stack
command. You must specify the name of the stack
that you want to delete. When you delete a stack, you delete the stack and all its
resources.
The following example deletes the myteststack
stack:
$
aws cloudformation delete-stack --stack-name myteststack
Note
You can't delete a stack that has termination protection enabled. For more information, see Protecting a stack from being deleted
If the deletion fails and returns a DELETE_FAILED
state, you can choose to
delete the stack by force using the deletion-mode
parameter. These are the
following values that can be used with deletion-mode
:
-
STANDARD
: Deletes the stack normally. This is the default deletion mode. -
FORCE_DELETE_STACK
: Deletes the stack and skips all resources that are failing to delete.
The following example force deletes the myteststack
stack using the
FORCE_DELETE_STACK
value with the deletion-mode
parameter:
$
aws cloudformation delete-stack --stack-name myteststack \ --deletion-mode FORCE_DELETE_STACK
When using FORCE_DELETE_STACK
, you may retain resources even if you have
deleted the stack. The following example shows the resources for the deleted stack:
$
aws cloudformation list-stack-resources --stack-name myteststack
The retained resources will show a DELETE_SKIPPED status.
For more information on listing resources associated with a stack, see Listing resources