Get a list of instances on ec2 without termination protection

amazon-web-servicesaws-cli

I want to get a list of instances on ec2 without termination protection.
Before I code something to do this, is there something hidden in the aws cli for this ?

Best Answer

It looks to me from the docs and my testing that you are looking for:

#aws ec2 describe-instance-attribute --instance-id <instanceid> --attribute disableApiTermination

This returns

<instanceid> DISABLEAPITERMINATION True

If termination protection is on. The documentation states, "If the value is true, you can't terminate the instance through the Amazon EC2 console, CLI, or API; otherwise, you can."

And you can modify the parameter with modify-instance-attribute. So...

#aws ec2 modify-instance-attribute --no-disable-api-termination --instance-id <instanceid>

or

#aws ec2 modify-instance-attribute --disable-api-termination --instance-id <instanceid>