Set of commands which are useful to clean after yourself when I tried to delete AWS Cloud Formation stacks when my infrasec role did not had all the needed permissions.
- List stacks which can be deleted (
DELETE_FAILED
status):aws cloudformation list-stacks | jq '.StackSummaries[] | select(.StackStatus=="DELETE_FAILED") | .StackName'
OR
-
List stacks which contain a specific string in their name:
aws cloudformation list-stacks | jq '.StackSummaries[] | select(.StackName | contains("bcol")) | .StackName'
-
List all S3 buckets from those stacks:
aws cloudformation list-stacks | jq '.StackSummaries[] | select(.StackStatus=="DELETE_FAILED") | .StackName' | get_s3_buckets_from_cf.sh
-
Delete all S3 buckets from stacks which have
DELETE_FAILED
status. 🔴 THIS IS A DESTRUCTIVE ACTION 🔴aws cloudformation list-stacks | jq '.StackSummaries[] | select(.StackStatus=="DELETE_FAILED") | .StackName' | ./get_s3_buckets_from_cf.sh | ./delete_s3_bucket.sh
-
Now, delete all Cloud formation stacks which have
DELETE_FAILED
status. 🔴 THIS IS A DESTRUCTIVE ACTION 🔴aws cloudformation list-stacks | jq '.StackSummaries[] | select(.StackStatus=="DELETE_FAILED") | .StackName' | ./delete_cf_stack.sh