How to List Stacks in AWS CDK

avatar

Borislav Hadzhiev

Sat Apr 24 20211 min read

Updated on Sat Apr 24 2021

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 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 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 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 cdk list --long

The --long 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 #

Add me on LinkedIn

I'm a Web Developer with TypeScript, React.js, Node.js and AWS experience.

Let's connect on LinkedIn

Join my newsletter

I'll send you 1 email a week with links to all of the articles I've written that week

Buy Me A Coffee