red888
red888

Reputation: 31570

aws cloudformation list-stacks gives me duplicate stacks?

I run this to get a list of my CF stacks:

aws cloudformation list-stacks --region us-east-1

I seem to be getting multiple results for the same stacks. I seems like its returning every version of each stack? How do I just get one result for each stack?

Upvotes: 2

Views: 2477

Answers (2)

helloV
helloV

Reputation: 52413

What makes you to think it returns duplicate stack names? Are there more than 100 stacks? The following should give just the stack names and should include the latest version.

aws cloudformation list-stacks --region us-east-1 --query 'StackSummaries[].StackName'

or to get the stack status:

aws cloudformation list-stacks --region us-east-1 --query 'StackSummaries[].[StackName,StackStatus]' --output text

To get only the stack with running stacks:

--stack-status-filter CREATE_COMPLETE

For more info: aws cloudformation list-stacks

You can use JMESPATH in --query to exclude stacks in certain states. Easiest way is to use grep.

aws cloudformation list-stacks --region us-east-1 --query 'StackSummaries[].[StackName,StackStatus]' --output text | grep -v DELETE_COMPLETE

To exclude multiple status:

aws cloudformation list-stacks --region us-east-1 --query 'StackSummaries[].[StackName,StackStatus]' --output text | egrep -v 'DELETE_COMPLETE| CREATE_COMPLETE| UPDATE_COMPLETE'

Upvotes: 7

spg
spg

Reputation: 9837

There is no conception of stack versions in CloudFormation. aws cloudformation list-stacks does not return duplicate stacks.

What happened is you probably had many stacks share the same name. For example, you can create a stack named "Stack1", delete it, and create a new stack with the same name "Stack1". Those 2 stacks will have different IDs, but will appear when calling list-stacks. The first one will have status DELETE_COMPLETE and have a different ID than the second stack.

Upvotes: 1

Related Questions