Skip to content

Instantly share code, notes, and snippets.

@eamonnfaherty
Created October 25, 2021 12:22
Show Gist options
  • Save eamonnfaherty/5eec7ff831adbd0eaa8e922433979fec to your computer and use it in GitHub Desktop.
Save eamonnfaherty/5eec7ff831adbd0eaa8e922433979fec to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -e
echo "Starting to prune change sets"
ALL_STACKS=$(aws cloudformation list-stacks --stack-status-filter CREATE_COMPLETE UPDATE_COMPLETE UPDATE_ROLLBACK_COMPLETE --query 'StackSummaries[].StackName' --output text)
for STACK_NAME in $ALL_STACKS
do
echo "Starting $STACK_NAME"
CHANGE_SET_NAMES=$(aws cloudformation list-change-sets --stack-name $STACK_NAME --query 'Summaries[?Status==`FAILED`].ChangeSetName' --output text)
for CHANGE_SET_NAME in $CHANGE_SET_NAMES
do
aws cloudformation delete-change-set --change-set-name $CHANGE_SET_NAME --stack-name $STACK_NAME
echo "Deleted $CHANGE_SET_NAME for $STACK_NAME"
done
echo "Finished $STACK_NAME"
done
echo "Finished pruning change sets"
@eamonnfaherty
Copy link
Author

This will delete all failed change sets for all stacks for the account/region it is run in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment