How to List Stacks in AWS CDK
Tags: aws, awscdk, cdk, iac
Published: 2023-11-25 11:25:35

---
title: How to List Stacks in AWS CDK
published: true
date: 2023-03-03 01:26:39 UTC
tags: #aws #awscdk #cdk #iac
canonical_url: https://blog.mikaeels.com/how-to-list-stacks-in-aws-cdk
---

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kxaeof203uivozr7rfws.jpeg)

AWS Cloud Development Kit (CDK) is a powerful tool that allows developers to define and deploy their infrastructure as code. One of the key features of CDK is the ability to create and manage stacks, which are collections of AWS resources that are deployed together. In this article, we will explore how to list stacks in AWS CDK.

To list stacks in AWS CDK, you can use the `cdk list` command. This command will display a list of all stacks that have been defined in your CDK application. The output will include the stack name, the stack environment, and the stack status.

To list all stacks in your CDK application, you can use the following command:

```
cdk list
```

<mark>Note</mark>, we could use the alias - `cdk ls`

This command will display a list of all stacks that have been defined in your CDK application, including the stack name, the stack environment, and the stack status.

If you want to list stacks in a specific environment, you can use the `-e` or `--environment` option. For example, to list stacks in the `prod` environment, you can use the following command:

```
cdk list -e prod
```

This command will display a list of all stacks that have been defined in the `prod` environment, including the stack name, the stack environment, and the stack status.

If you want to list stacks in a specific region, you can use the `-r` or `--region` option. For example, to list stacks in the `us-east-1` the region, you can use the following command:

```
cdk list -r us-east-1
```

This command will display a list of all stacks that have been defined in the `us-east-1` region, including the stack name, the stack environment, and the stack status.

In addition to listing stacks, the `cdk list` command also allows you to filter the output by stack status. You can use the `-s` or `--status` option to filter the output based on the stack status. For example, to list only stacks that are in the `CREATE_COMPLETE` status, you can use the following command:

```
cdk list -s CREATE_COMPLETE
```

This command will display a list of all stacks that are in the `CREATE_COMPLETE` status, including the stack name, the stack environment, and the stack status.

Another useful option when using the `cdk list` command is the `--long` option. This option will display additional information about each stack, such as the stack's id, name, AWS account, region, environment, and where the stack is deployed.

For example, if you want to view all the stacks in your CDK application, along with additional information, you can use the following command:

```
cdk list --long
```

The `--long` flag outputs information about the environment (`account`and `region`) our stacks belong to:

```
- id: my-stack-prod
  name: my-stack-prod
  environment:
    account: '123456789'
    region: us-east-1
    name: aws://123456789/us-east-1

- id: my-stack-dev
  name: my-stack-dev
  environment:
    account: '123456789'
    region: us-east-1
    name: aws://123456789/us-east-1
```

In conclusion, the `cdk list` command is a powerful tool that allows you to list stacks in AWS CDK. You can use this command to list all stacks in your CDK application, list stacks in a specific environment, list stacks in a specific region, and filter the output by stack status. This makes it easy to manage your stacks and ensure that your infrastructure is deployed correctly.