Last active
November 19, 2020 22:55
-
-
Save rjurney/c4e90a1b62842fbf939a0767a2626b08 to your computer and use it in GitHub Desktop.
Bash script to disable termination protection and then terminate all instances in all regions :)
This file contains 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
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
@cappellaiomatto Fixed, thanks!