How to Detach an AWS EC2 Instance from Auto Scaling Group

Learn how to detach an AWS EC2 instance from its Auto Scaling group and load balancer for maintenance and testing. Follow these simple steps to get started.

Patrick Londa
Author
Jul 21, 2022
 • 
 min read
Share this post

If you need to test or audit a specific AWS EC2 instance, you may need to detach it from its Auto Scaling group and deregister its associated load balancer. 

In this guide, we'll outline the steps you can take to isolate the instance as part of general maintenance.

Blink Automation: Detach an EC2 Instance from a Load Balancer
Blink + AWS
Try This Automation

When Detaching an EC2 Instance Makes Sense

As your team strives for continual process improvements and alignment between business needs and security concerns, it's important to have firm control over interactions throughout the system.

Detaching AWS EC2 instances from their Auto Scaling group allows you to test them independently or while attached to another existing instance. This capability could prove helpful when you need to understand precisely how other instances influence an instance’s behavior in its Auto Scaling group.

Separating the EC2 instance from its autoscaling group is also helpful for performing routine testing and maintenance since it helps determine an unaffected baseline for the instance’s performance.

Additionally, detaching the instance from the Auto Scaling group deregisters the load balancer associated with the group. Whatever your reason for wanting to detach an AWS EC2 instance from its Auto Scaling group, the process is relatively straightforward, with only a few caveats.

Getting a List of Running EC2 Instances

The first step in detaching the instances is determining which instances are running. You can use either the AWS CLI or Console to get this information.

Using the AWS CLI

The following command typed in the AWS command-line interface will provide you with a listing of all the instances that are currently active:

aws autoscaling describe-auto-scaling-instances

Executing this command returns essential information about all of your instances:

  • Instance ID (InstanceID): A unique ID number assigned to the instance
  • Auto Scaling group name (AutoScalingGroupName): The name of the autoscaling group
  • Health Status (HealthStatus): Whether the instance is healthy or not
  • Life Cycle State (LifeCycleState): Whether the instance is active or inactive

You will also see additional information about the template used to create the instance, the zone where it's available, and whether the instance is available for automatic scaling.

Using the AWS Console

  1. Log in to the Amazon EC2 Auto Scaling console.
  2. You'll see a list of your Auto Scaling groups. Select the check box next to the group from which you want to detach an instance.
  3. You'll see a split pane at the bottom of the Auto Scaling groups page. Go to the Instance management tab.

From this screen, you'll be able to detach specific instances from your Auto Scaling groups following the next set of steps.

Detaching the EC2 Instance from its Auto Scaling Group

Now that you have a list of your instances, you can proceed with detaching the ones you want from their Auto Scaling group.

You can now reduce, or decrement, the desired capacity for the Auto Scaling group by the number of instances you are detaching. Amazon EC2 Auto Scaling will launch instances to replace any that you detach if you choose not to decrement the capacity. You must ensure that you don't decrease the size of the autoscaling group below its minimum capacity without first decrementing the minimum capacity.

You can perform this task from the command line or the console.

Using the AWS CLI

With the addition of a few parameters garnered from the previous command, the "detach-instances" command will allow you to detach one or multiple EC2 instances:

aws autoscaling detach-instances \

Add the following parameters with the required information to the command:

--instance-ids <ID VALUE> \
--auto-scaling-group-name <GROUP NAME> \
--should-decrement-desired-capacity

Using the AWS Console

The last console steps left you at the Instance management tab on the Auto Scaling groups page.

  1. In the Instances group, choose the desired instance.
  2. Select Actions and then Detach instance.
  3. To decrement the desired capacity, leave the check box next to launch a replacement instance unchecked.

Detaching EC2 Instances Seamlessly with Blink

Detaching an EC2 instance from its Auto Scaling group and load balancer is just the start of being able to conduct testing and maintenance. By relying on a manual process, you are less likely to make this exercise a routine practice.

With Blink, you can handle this detachment task with this simple automation. You can also add actions to the automation to kick off whatever testing or maintenance activities once the instance is detached.

Blink Automation: Detect AWS Elastic Load Balancers with No Targets and Send Report on Slack
Blink Automation: Detect AWS Elastic Load Balancers with No Targets and Send Report on Slack

When this automation runs, it executes the following steps:

  1. Detaches the specific instance from its autoscaling group.
  2. Detaches the instance from its load balancer.

You can use and customize any of the 5K automations in the Blink library, or build automations from scratch to fit your unique needs.

Get started with Blink today to see how easy automation can be.

Expert Tip