Skip to content

Instantly share code, notes, and snippets.

@stekern
Created April 26, 2023 10:46
Show Gist options
  • Save stekern/66df10e8cc2126a905beb0960b0b37ed to your computer and use it in GitHub Desktop.
Save stekern/66df10e8cc2126a905beb0960b0b37ed to your computer and use it in GitHub Desktop.
List all CloudFormation stacks in all enabled regions
#!/usr/bin/env bash
#
# Script that uses the AWS CLI to list all active CloudFormation stacks
# in all enabled regions.
#
set -euo pipefail
IFS=$'\n\t'
regions="$(aws account list-regions --region-opt-status-contains "ENABLED" "ENABLED_BY_DEFAULT" --query "Regions[].[RegionName]" --output text && printf '\0')"
read -r -d '' -a regions < <(aws account list-regions --region-opt-status-contains "ENABLED" "ENABLED_BY_DEFAULT" --query "Regions[].[RegionName]" --output text && printf '\0')
for region in "${regions[@]}"; do
echo "[$region] Finding CloudFormation Stacks"
read -r -d '' -a stacks < <(aws cloudformation list-stacks --region "$region" --query "StackSummaries[?!contains(keys(@), 'DeletionTime')].[StackName]" --output text && printf '\0')
test -z "${stacks:-}" && continue
for stack in "${stacks[@]}"; do
echo " $stack"
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment