Skip to content

Instantly share code, notes, and snippets.

@kylemclaren
Forked from rjurney/terminate_all_ec2.sh
Created November 19, 2020 22:55
Show Gist options
  • Save kylemclaren/e903a11d6a4720981bb9a6a979779969 to your computer and use it in GitHub Desktop.
Save kylemclaren/e903a11d6a4720981bb9a6a979779969 to your computer and use it in GitHub Desktop.
Bash script to disable termination protection and then terminate all instances in all regions :)
for region in `aws ec2 describe-regions | jq -r .Regions[].RegionName`
do
echo "Terminating region $region..."
aws ec2 describe-instances --region $region | \
jq -r .Reservations[].Instances[].InstanceId | \
xargs -L 1 -I {} aws ec2 modify-instance-attribute \
--region $region \
--no-disable-api-termination \
--instance-id {}
aws ec2 describe-instances --region $region | \
jq -r .Reservations[].Instances[].InstanceId | \
xargs -L 1 -I {} aws ec2 terminate-instances \
--region $region \
--instance-id {}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment