Created
February 2, 2021 18:16
-
-
Save ameir/15d5721ccef43448b27c23a0eb192655 to your computer and use it in GitHub Desktop.
Delete CloudFormation stacks based on prefix or regex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -euo pipefail | |
export AWS_PAGER="" | |
REGEX="^prefix-" | |
WAIT=true | |
stacks=$(aws cloudformation describe-stacks --query Stacks[].StackName --output=text) | |
for stack in $stacks; do | |
if [[ $stack =~ $REGEX ]]; then | |
echo "Deleting stack ${stack}..." | |
aws cloudformation delete-stack --stack-name $stack | |
if $WAIT; then | |
echo "Waiting for stack ${stack} to delete..." | |
aws cloudformation wait stack-delete-complete --stack-name $stack | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment