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;
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?
Select the instance, and choose Actions, Instance Settings, Change Termination Protection. Choose Yes, Disable.
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.
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.
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.
According to the documentation
To disable termination protection for a running or stopped instance
Select the instance, and choose Actions, Instance Settings, Change Termination Protection.
Choose Yes, Disable.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With