Skip to content

Instantly share code, notes, and snippets.

@pedroagabreu
Last active November 20, 2015 15:35
Show Gist options
  • Save pedroagabreu/11d61c7daecd047835f5 to your computer and use it in GitHub Desktop.
Save pedroagabreu/11d61c7daecd047835f5 to your computer and use it in GitHub Desktop.
Mass terminate AWS EC2 instances with active termination protection
#!/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