Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

amazon-ec2

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?

like image 461
ilam engl Avatar asked Apr 20 '21 11:04

ilam engl


People also ask

How do I edit Disableapitermination?

Select the instance, and choose Actions, Instance Settings, Change Termination Protection. Choose Yes, Disable.

How do I remove a terminated EC2 instance from my dashboard?

To delete terminated EC2 Instances, locate the instance you want to delete in the EC2 Console under the Instances page. Click on the instance and select the Terminate option. Once you've selected “terminate,” you will receive a pop-up confirmation. Click “yes” to confirm.

What happens when EC2 instance is terminated?

After you terminate an instance, it remains visible in the console for a short while, and then the entry is automatically deleted. You cannot delete the terminated instance entry yourself.

How do I enable termination protection on AWS EC2?

To enable termination protection for an EC2 instance, open the EC2 dashboard and click on the instance you want to protect. Next, choose Instance Settings from the Actions menu, and then choose the Change Termination Protection option from the resulting menu, as shown in Figure 3.


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

like image 127
ilam engl Avatar answered Nov 24 '22 21:11

ilam engl


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
like image 39
avivamg Avatar answered Nov 24 '22 21:11

avivamg