How to use “delete-stack” command in AWS CLI?

cloudfromation Is a web service that is used for managing and auditing resources. User can manage AWS resources by creating templates in JSON or YAML formats. This file contains the required configuration for AWS resources. In cloud formationThere are multiple stacks within a template.

quick outline

In this article we will learn about:

A heap It contains information about the resources required to deploy applications. These stacks can be managed through the console or AWS CLI. One of the administrative actions to manage these tasks through the AWS CLI is to delete the stack. AWS supports CLI “delete-stack” Ordering CloudFormation.

Read more: How to get started with AWS CloudFormation?

What is the “delete-stack” command in AWS CLI?

“delete-stack” The command in the AWS CLI is used to delete a specified stack from the CloudFormation dashboard. On successful execution of this command, no output is returned. However, the user can confirm the deletion of the stack by visiting the CloudFormation dashboard.

How to use “delete-stack” command in AWS CLI?

“delete-stack” The commands are simple to use and easy to understand. The user can specify the name and area of ​​the stack to be deleted using various parameters.


AWS CloudFormation delete-stack –stack-name <Option,


Various options are supported by it “delete-stack” Permission. Following is a brief description of the options:

Option Description
-stack-name This parameter inputs the name or unique ID of the stack.
-Maintain resources This parameter is for the stack that is in “DELETE_FAILED” State. It accepts a list of resource names that the user wants to retain when CloudFormation deletes the stack.
–role-earn CloudFormation also deletes a stack by IAM role ARN.

The –role-arn parameter is used for this purpose.

-client-request-token This parameter is used to retry deleting a stack from the CloudFormation dashboard.
-cli-input-json This parameter is used to provide multiple JSON instructions to the AWS service at once. The template used by this parameter is generated by “-generate-cli-token”.
-generate-cli-skeleton -generate-cli-token is used to create a template or skeleton to provide several JSON directives to the service.

there are also global options Available for use with this order. Such options can be used with multiple commands and hence, are named global options. AWS Documentation Discusses these options in detail.


In this part of the article, we will explore the different ways of using it “delete-stack” Commands in AWS CLI:

Example 1: How to delete a stack using AWS CLI?

To delete a stack, first create a stack by going here “Cloud Building” Service from the AWS Management Console. To learn more about creating a stack, check out this article: ” How to get started with AWS CloudFormation?”

For this demo, we have already created a stack named “stack01”,

The command to delete a stack using AWS CLI is as follows:

AWS CloudFormation delete-stack –stack-name <stackname,

Comment: replace the <स्टैकनाम> with the name of your stack AWS CloudFormation.


To verify whether the stack has been successfully deleted, go to stack dashboard in aws cloud formation, Here, the stack has been successfully removed:

Example 2: How to delete a stack in a specific region using AWS CLI?

Often, applications and stacks are running in regions other than the default AWS regions. “delete-stack” The command also helps the user to delete stacks in different regions by specifying the AWS region name “-Area” Parameters. The order is given as follows:

AWS Cloud Formation delete-stack –stack-name stack03 –Area AP-Southeast-1

Comment: replace the “stack03” With the name of your CloudFormation stack. Similarly, replace “ap-southeast-1” With the name of the AWS region.


Example 3: How to delete stack using -profile in AWS CLI?

In AWS, the user can also use the -profile parameter to delete a stack in CloudFormation. For this purpose, create an IAM user and then configure the user in the AWS CLI using the -profile parameter. It is worth noting here that the created IAM user must be equipped with

“AmazonCloudFormationFullAccess” Permission to delete stack.

For this demo, we have already created and configured -profile the user:

To delete the stack using -profile user provide the following command to the terminal:

AWS CloudFormation delete-stack –stack-name <stackname, –Area <AWSRegionName,

Comment: replace the <स्टैकनाम> With your CloudFormation Pile name. Similarly, in , Provide the name of your AWS region in which the stack is created


That's all from this guide.


delete-stack The command deletes a specific stack in a specific area from the CloudFormation dashboard. This command does not produce any output on successful execution. For AWS users, this command can help manage costs and monitor services by removing idle resources. This article is a step-by-step guide to implement it delete-stack Commands in AWS CLI.

Add comment

By Ranjan