How to List Stacks in AWS CDK

avatar

Borislav Hadzhiev

Thu Apr 14 20221 min read

Updated - Thu Apr 14 2022

List Stacks in AWS CDK #

A CDK App can consist of one or more stacks.

In order to list the stacks in a CDK application we have to use the cdk list command:

shell
npx aws-cdk list

If we have a simple CDK application consisting of 2 stacks:

const app = new cdk.App(); new MyCdkStack(app, 'my-stack-dev', { stackName: 'my-stack-dev', }); new MyCdkStack(app, 'my-stack-prod', { stackName: 'my-stack-prod', });

The output from the command looks like:

cdk list output

Alternatively, we could use the alias - cdk ls:

shell
npx aws-cdk ls

The output from the command is the same:

cdk ls output

We can look at all of the available flags of the cdk list command by appending the --help flag.

shell
npx aws-cdk list --help
This method applies to all cdk commands - just append the --help flag to the end of the command to get the list of options we can pass.

The flag that I use the most is --long, i.e.:

shell
npx aws-cdk list --long

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

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

Further Reading #

Use the search field on my Home Page to filter through my more than 1,000 articles.