Skip to content

Instantly share code, notes, and snippets.

@edenzik
Created November 14, 2016 18:07
Show Gist options
  • Save edenzik/5d8cfc78d206e69c3a178bb39b1e37e9 to your computer and use it in GitHub Desktop.
Save edenzik/5d8cfc78d206e69c3a178bb39b1e37e9 to your computer and use it in GitHub Desktop.
Disable API protection on a lot of instances by filtering them via AWS Cli
# First, filter out the AMI ID's to a file (you should figure out a way to do this with xargs)
aws ec2 describe-instances --query 'Reservations[].Instances[].[InstanceId] ' --output text --filters Name="instance-state-name",Values="stopped"
# Now loop through them
while read l; do aws ec2 modify-instance-attribute --disable-api-termination --instance-id $l; done < ami
@duncanallwood
Copy link

Expanding on what Huevos says:
--disable-api-termination Prevents instance termination from the API
--no-disable-api-termination Allows instance termination from the API

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment