Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS CLI list only the name of current running cloudformation stacks?

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.

like image 722
Alex Avatar asked Apr 05 '17 19:04

Alex


1 Answers

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

  • AWS Documentation - aws cloudformation list-stacks
  • AWS Documentation - Controlling Command Output from the AWS Command Line Interface
like image 62
Anthony Neace Avatar answered Sep 22 '22 20:09

Anthony Neace