Last active
November 20, 2015 15:35
-
-
Save pedroagabreu/11d61c7daecd047835f5 to your computer and use it in GitHub Desktop.
Mass terminate AWS EC2 instances with active termination protection
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
#!/bin/bash | |
# terminate instances | |
for i in i-aaaaaa i-bbbbbb i-cccccc ...; do aws ec2 modify-instance-attribute --instance-id $i --no-disable-api-termination; done | |
aws ec2 terminate-instances --instance-ids i-aaaaaa i-bbbbbb i-cccccc ... | |
# release elastic ips | |
for i in $(cat ips); do aws ec2 describe-addresses --public-ip $i |grep AllocationId |cut -d: -f2 |tr -d \"; done > eipalloc | |
for i in $(cat eipalloc); do aws ec2 release-address --allocation-id $i; done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment