Some of our AWS users got this error “can’t terminate EC2 instance”, there are mainly three causes for this issue.
Causes for Can’t terminate EC2 instance issue?
- When an instance is in stopping ot pending state.
- Termination protection is enabled for the instance.
- Incorrect permissions on the AWS Identity and Access Management (IAM) policy are attached to the role or user that attempting to terminate the instance.
- When an instance is in stopping or pending state :
If your instance appears to be stuck in the stopping state, first you should stop the instance. You can stop an EC2 instance by choosing the instance and selecting the stop option from the instance state menu.
After successfully stopping the instance you can terminate the instance.
If the instance is pending for more than 30 minutes after you attempt to launch it. Then run the stop or terminate command from the AWS CLI.
In order to assist with the troubleshooting, enable the –debug option.
- Termination protection is enabled for the instance :
If termination protection is enabled for an instance you can’t remove that instance.
To disable the termination protection for running or stopped instance, follow the below steps,
Select the instance.
Choose instance settings from Actions and select change termination protection. Then choose yes, disable option there.
When we try to terminate the instance, the IAM policy attached to the user or role must allow ec2:TerminateInstances API.
From the policy section, you can choose the corresponding policy attached to your EC2 instance. From there you can edit the policy by choosing the permissions tab.
If you are still facing trouble with terminating your EC2 instance, no need to worry our technical experts will help you to resolve the issue fastly.