If you’re like me and work with AWS environments with numerous CloudFormation stacks running in many regions globally, then you’re often going to want to audit what stacks you have running. I thought I would share my method of doing this, using the following bash snippet to run a couple of AWS CLI commands.
#!/bin/bash # Store list of regions into $REGIONS variable REGIONS=$(aws ec2 describe-regions --query "Regions[].{Name:RegionName}" --output text) # Iterate through list of $REGIONS to output CloudFormation stacks for REGION in $REGIONS; do echo $REGION; aws cloudformation list-stacks --region $REGION --output table done
If you’re looking for specific stacks, i.e. where the StackName equals something specific, such as “NETWORKING” in this example, you can do this use the query option built into the AWS CLI:
[...] for REGION in $REGIONS; do echo $REGION; aws cloudformation list-stacks --region $REGION --query "StackSummaries[?StackName=='NETWORKING']" --output table done
More information on the list-stacks API.
Leave A Comment