Delete stack instances using the CloudFormation console or AWS CLI
You can delete stack instances from a stack set using either the CloudFormation console or the AWS CLI.
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.
Delete stack instances using the CloudFormation console
Sign in to the AWS Management Console and open the AWS CloudFormation console at https://console.aws.amazon.com/cloudformation
. -
On the navigation bar at the top of the screen, choose the AWS Region you created the stack set in.
-
From the navigation pane, choose StackSets. On the StackSets page, select the stack set.
-
With the stack set selected, choose Delete stacks from StackSet from the Actions menu.
-
On the Set deployment options page, choose the accounts to delete stack instances from.
-
[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 Organizational units (OUs), specify the target OU IDs.
Note
StackSets also deletes stack instances from any child OUs of the specified target OUs.
-
For Specify regions, choose the Regions you want to delete stack instances from.
-
For Deployment options:
-
For Maximum concurrent accounts, modify the maximum concurrent accounts as needed.
-
For Failure tolerance, modify the failure tolerance as needed.
-
For Retain stacks, choose whether to enable this option 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 enabling 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 Requirements for importing a stack into a stack set.
-
For Region concurrency, modify the region concurrency as needed.
-
For Concurrency mode, modify the concurrency mode as needed.
-
-
Choose Next.
-
-
On the Review page, review your choices. To make changes, choose Edit on the related section.
-
When you are ready to remove the stack instances from your stack set, 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
option to DELEGATED_ADMIN
each time you run a StackSets
command.
--call-as
DELEGATED_ADMIN
-
Use the delete-stack-instances command. For
--stack-set-name
, specify the stack set name.Because
--retain-stacks
is required for the delete-stack-instances command, if you don't want to retain (save) stacks, add--no-retain-stacks
. In this example, we add the--no-retain-stacks
option, because we aren't retaining any stacks.For
--regions
, specify the regions you want to delete stack instances from. In this example, US West (Oregon) Region and US East (N. Virginia) Region.[Self-managed permissions] For the
--accounts
option, specify the accounts you used to create your stack set.aws cloudformation delete-stack-instances --stack-set-name
my-stackset
\ --accounts'["account_ID_1","account_ID_2"]'
--regions'["us-west-2","us-east-1"]'
\ --no-retain-stacks[Service-managed permissions] For
--deployment-targets
, specify the organization (root) ID or OU IDs you created stack instances in.aws cloudformation delete-stack-instances --stack-set-name
my-stackset
\ --deployment-targets OrganizationalUnitIds='["ou-rcuk-1x5jlwo", "ou-rcuk-slr5lh0a"]'
--regions'["us-west-2","us-east-1"]'
\ --no-retain-stacksNote
StackSets also deletes stack instances from any child OUs of the specified target OUs.
To specify your preferences for how CloudFormation performs this stack set operation, specify the
--operation-preferences
option, as in the following example. For the purposes of this example, we're using count, not percentage. To apply percentages instead, useFailureTolerancePercentage
orMaxConcurrentPercentage
.--operation-preferences
FailureToleranceCount=0,MaxConcurrentCount=1
Note
The value of
MaxConcurrentCount
is dependent on the value ofFailureToleranceCount
.MaxConcurrentCount
is at most one more thanFailureToleranceCount
. -
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 your delete-stack-instances command.aws cloudformation describe-stack-set-operation --stack-set-name
my-stackset
\ --operation-idddf16f54-ad62-4d9b-b0ab-3ed8e9example