Delete stack instances using the AWS Management Console or AWS CLI
You can delete stack instances from a stack set in either the AWS Management Console, or by using AWS CloudFormation commands in the AWS CLI. In this procedure, we will delete all stacks.
For a stack set with service-managed permissions, if you delete stack instances from a top-level organizational unit (OU), the OU is removed as a target of the stack set.
Topics
Delete stack instances using the AWS Management Console
Open the AWS CloudFormation console at https://console.aws.amazon.com/cloudformation
. -
Choose StackSets from the navigation pane. On the StackSets page, select the stack set that you created in Create a stack set using the AWS Management Console or AWS CLI.
-
With the stack set selected, choose Delete stacks from StackSet from the Actions menu.
-
On the Set deployment options page, choose the accounts from which to delete stack instances.
-
[Self-managed permissions] For Accounts, choose Deploy stacks in accounts. Paste your target account numbers in the text box, separating multiple numbers with commas.
[Service-managed permissions] For Accounts, choose Deploy stacks in organizational units. Paste the IDs of the OUs that your stack set targets.
Note
StackSets also deletes stack instances from any child OUs of the specified target OUs.
-
For Deployment regions, choose the Regions from which you want to delete stack instances. In this case, US East (N. Virginia) Region and US West (Oregon) Region.
-
For Deployment options:
-
For Maximum concurrent accounts, keep the default values of Number and 1.
-
For Failure tolerance, keep the defaults of Number and 0.
In the Retain stacks area, keep the default setting of disabled.
When you are deleting stacks from a stack set, the Retain stacks option lets you choose to remove the stack instances from your stack set, but save the stacks and their associated resources. When you save stacks from a stack set by choosing the Retain stacks option, the stack's resources stay in their current state, but the stack is no longer part of the stack set. To reassociate a stack or add an existing stack to a stack set, see Importing a stack into AWS CloudFormation StackSets.
Choose Next.
-
-
-
On the Review page, review your choices and choose Submit.
-
After stack deletion is finished, you can verify that stack instances were deleted from your stack set in the StackSet detail page, on the Stack instances tab.
Delete stack instances using the AWS CLI
When acting as a delegated administrator, you must set the --call-as
parameter to DELEGATED_ADMIN
each time you run a StackSets
command.
--call-as
DELEGATED_ADMIN
-
Run the
delete-stack-instances
command. For--stack-set-name
, specify the stack set namemy-awsconfig-stackset
.Set the failure tolerance and maximum concurrent accounts by setting
FailureToleranceCount
to0
, andMaxConcurrentCount
to1
in the--operation-preferences
parameter, as shown in the following example. To apply percentages instead, useFailureTolerancePercentage
orMaxConcurrentPercentage
. For the purposes of this walkthrough, we are using count, not percentage.Note
The value of
MaxConcurrentCount
is dependent on the value ofFailureToleranceCount
.MaxConcurrentCount
is at most one more thanFailureToleranceCount
.Because
--retain-stacks
is a required parameter ofdelete-stack-instances
, if you don't want to retain (save) stacks, add--no-retain-stacks
. In this walkthrough, we add the--no-retain-stacks
parameter, because we aren't retaining any stacks.[Self-managed permissions] Replace
account_ID
with the accounts you used to create your stack set in Create a stack set using the AWS Management Console or AWS CLI.aws cloudformation delete-stack-instances --stack-set-name my-awsconfig-stackset --accounts '["
0123456789012
"]' --regions '["eu-west-1
"]' --operation-preferences FailureToleranceCount=0,MaxConcurrentCount=1 --no-retain-stacks[Service-managed permissions] For
--deployment-targets
, specify the organization (root) ID or OU IDs in which you created stack instances.Note
StackSets also deletes stack instances from any child OUs of the specified target OUs.
aws cloudformation delete-stack-instances --stack-set-name my-awsconfig-stackset --deployment-targets OrganizationalUnitIds='["
ou-rcuk-1x5jlwo
", "ou-rcuk-slr5lh0a
"]' --regions '["eu-west-1"]' --no-retain-stacks -
Optionally, after stack deletion is finished, verify that stack instances were deleted from your stack set by running the
describe-stack-set-operation
command to show the status and results of the delete stacks operation. For--operation-id
, use the operation ID that was returned by yourdelete-stack-instances
command.aws cloudformation describe-stack-set-operation --stack-set-name
stackSetName
--operation-idddf16f54-ad62-4d9b-b0ab-3ed8e9example