How do I remove a terminated EC2 instance from my Auto Scaling group?

Last updated: 2019-04-15

I have an Amazon Elastic Compute Cloud (Amazon EC2) instance that was terminated. However, the instance shows as healthy (Healthy) and in the standby state (InStandby) in the Amazon EC2 console. How do I remove this terminated instance from my Amazon EC2 Auto Scaling (EC2 Auto Scaling) group?

Short Description

EC2 Auto Scaling doesn’t perform health checks for instances in the standby state. EC2 Auto Scaling isn’t aware of instance terminations for instances in standby.

You can remove terminated instances from your EC2 Auto Scaling group that are still listed as healthy and in standby using one of the following methods:

  • Terminate the instance using the AWS Command Line Interface (AWS CLI).
  • Detach the instance from your EC2 Auto Scaling group, which removes it from the EC2 Auto Scaling console.
  • Take the instance out of the standby state, which allows Auto Scaling to discover the instance termination using health checks.

Resolution

Remove the terminated instance from your EC2 Auto Scaling group using the appropriate method for your use case.

Terminate the instance

Terminate your instance using the following command. Be sure to replace YOUR-INSTANCE-ID with your instance's resource ID.

aws autoscaling terminate-instance-in-auto-scaling-group --instance-id YOUR-INSTANCE-ID --no-should-decrement-desired-capacity

Important: If you’ve configured the lifecycle hook EC2_INSTANCE_TERMINATING for your EC2 Auto Scaling group, use CompleteLifecycleAction to remove the instance from the group immediately.

Detach the instance

Detach your instance from the EC2 Auto Scaling group using the following command. Be sure to replace YOUR-INSTANCE-ID with your instance's resource ID and YOUR_ASG_NAME with your EC2 Auto Scaling group's name.

aws autoscaling detach-instances --instance-ids YOUR-INSTANCE-ID --no-should-decrement-desired-capacity --auto-scaling-group-name YOUR-ASG-NAME

Take the instance out of standby

1.    Edit your EC2 Auto Scaling group’s maximum size using the AWS CLI or the Amazon EC2 console. When you put the instance back into service, the desired capacity is incremented by 1 and must not exceed the maximum size value for the group. Set the maximum size to the current value + the number of instances being returned to service (1), or you might receive an error similar to:

An error occurred (ValidationError) when calling the ExitStandby operation: AutoScalingGroup YOUR-ASG-NAME has min-size=1, max-size=1, and desired-size=1. To place in service 1 instance, please update the AutoScalingGroup sizes appropriately.

Note: A replacement instance is launched to match the desired capacity after your intended instance is terminated.

2.    Take your instance out of standby using the following command. Be sure to replace YOUR-INSTANCE-ID with your instance's resource ID and YOUR_ASG_NAME with your EC2 Auto Scaling group's name.

aws autoscaling exit-standby --instance-ids YOUR-INSTANCE-ID --auto-scaling-group-name YOUR-ASG-NAME

Did this article help you?

Anything we could improve?


Need more help?