Failed to terminate ec-2 instance: How to modify its 'disableApiTermination' attribute from EC2 Dashboard?

Viewed 15589

I opened a free tier instance for some practice.

I tried to terminate it, as I've done many times successfully.

But upon selecting Terminate instance from the dropdown;

enter image description here

I got the following error:

Failed to terminate the instance <instance id>
The instance '<instance id>' may not be terminated. Modify its 'disableApiTermination' instance attribute and try again.

Where can I find the disableApiTermination attribute?

2 Answers

According to the documentation

To disable termination protection for a running or stopped instance

  1. Select the instance, and choose Actions, Instance Settings, Change Termination Protection.

  2. Choose Yes, Disable.

enter image description here

enter image description here

Solution: you need to disable api termination protection by changing instance attribute, I'll demonstrate how to do it with aws api. (documentation attached)

instance_id=$(aws ec2 describe-instances \
               --filter "Name=tag:Name,Values=instance-name-example" \
               --query "Reservations[].Instances[].InstanceId[]" \
               --output text)
               
aws ec2 modify-instance-attribute --instance-id $instance_id  --no-disable-api-termination
Related