4
votes

I'm building up to a larger AWS CLI job but one of the building blocks is stumping me;

How do I get a list of just the names of every currently running AWS Cloudformation stack?

I can list the stacks just fine with the following, but I can't get a query to pair it down to just the stack name.

aws cloudformation list-stacks --stack-status-filter CREATE_COMPLETE --output text

I could cut the resulting table down in bash, but I'd love a more elegant aws solution if it exists.

2

2 Answers

8
votes

You can add the query parameter to that same query to narrow the result set to only the StackName.

Per @idbehold, you will also need to include all stack status filters except for CREATE_FAILED and DELETE_COMPLETE to truly capture all current stacks. These only need to be delimited by spaces.

Query:

"StackSummaries[*].StackName"

Full Example:

aws cloudformation list-stacks --stack-status-filter CREATE_IN_PROGRESS CREATE_COMPLETE ROLLBACK_IN_PROGRESS ROLLBACK_FAILED ROLLBACK_COMPLETE DELETE_IN_PROGRESS DELETE_FAILED UPDATE_IN_PROGRESS UPDATE_COMPLETE_CLEANUP_IN_PROGRESS UPDATE_COMPLETE UPDATE_ROLLBACK_IN_PROGRESS UPDATE_ROLLBACK_FAILED UPDATE_ROLLBACK_COMPLETE_CLEANUP_IN_PROGRESS UPDATE_ROLLBACK_COMPLETE REVIEW_IN_PROGRESS --query "StackSummaries[*].StackName"

Further Reading

0
votes
    # foreach stack in prod describe stack resources
    while read -r stack ; do \
    echo -e "\nSTART $stack\n" ;\
    aws cloudformation describe-stack-resources --stack-name $stack --profile prd ; \
    echo -e "\nSTOP  $stack \n" ; done \
    < <(aws cloudformation list-stacks --stack-status-filter CREATE_COMPLETE \
    --query "StackSummaries[*].StackName" --profile prd \
    | perl -ne 's/\s+/\n/g;print'| sort)