Why can't I terminate my EC2 instance?

2 minute read
0

I want to terminate my Amazon Elastic Compute Cloud (Amazon EC2) instance.

Resolution

Your Amazon EC2 instance might not terminate for the following reasons:

  • The instance is in a stopping or pending state.
  • Termination protection is turned on for the instance.
  • There are incorrectly configured permissions in the AWS Identity and Access Management (IAM) policy attached to the role or user that's changing the instance state.
  • The instance is part of an Auto Scaling group.

The instance is in a stopping or pending state

You can force stop an EC2 instance when the instance appears to be stuck in the stopping or pending state. To force stop the instance, use the Amazon EC2 console or the AWS Command Line Interface (AWS CLI). After you successfully stop the instance, you can terminate it.

Note: When you create or start an instance, it might remain in the pending state for more than 30 minutes.

To force an instance to stop in the AWS CLI, run the stop-instances command with the --force option. After the instance stops, run the terminate-instances command.

Note: If you receive errors when running AWS CLI commands, make sure that you're using the most recent version of the AWS CLI.

Or, you can run AWS CLI commands in AWS CloudShell if your AWS Region is supported.

Termination protection is turned on for the instance

You can't terminate an EC2 instance when termination protection is turned on. For more information, see Enable termination protection and follow the instructions in To disable termination protection for a running or stopped instance.

There are incorrectly configured permissions in the IAM policy attached to the role or user that's changing the instance state

The IAM role or IAM user that's attempting to terminate an EC2 instance must have an IAM policy that allows the TerminateInstances API. For information on editing IAM policies, see Editing IAM policies.

The instance is part of an Auto Scaling group

When you terminate an EC2 instance that's a part of an Auto Scaling group, a replacement instance might be launched by the Auto Scaling group. This is an expected behavior of the Auto Scaling group to maintain the desired count. Run the terminate-instance-in-auto-scaling-group AWS CLI command to terminate the instance and adjust the group size.

AWS OFFICIAL
AWS OFFICIALUpdated 9 months ago