Sometimes you may reach to max count of changesets in CloudFormation. When using AWS CLI or AWS Console, it is possible to delete changesets one by one. However, how can one delete all changesets associated with a stack without removing the stack itself?
On Mac:
Install jq with brew:
brew install jq
You have to install aws-cli and configure your access key and secret
Create a file like clear-changeset.sh and paste below code into it:
aws cloudformation list-change-sets --stack-name YOUSTACKNAME > STACK_RESULT.json
max_processes=4
count=0
for item in $(cat STACK_RESULT.json | jq -r '.Summaries[].ChangeSetName'); do
echo "Deleting change set: $item"
aws cloudformation delete-change-set --stack-name YOUSTACKNAME --change-set-name "$item" &
((count++))
if ((count >= max_processes)); then
wait
count=0
fi
done
wait
run the clear-changeset.sh file like:
./clear-changeset.sh
Attention:
Check the .sh file permissions to run it (chmod 0755 clear-changeset.sh
).