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.
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:
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
- Log in to the Amazon EC2 Auto Scaling console.
- 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.
- 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:
Add the following parameters with the required information to the command:
Using the AWS Console
The last console steps left you at the Instance management tab on the Auto Scaling groups page.
- In the Instances group, choose the desired instance.
- Select Actions and then Detach instance.
- 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.
When you create a free Blink account, you can turn this detachment task into a no-code/low-code automation that is a couple clicks away. You can then automatically kick off whatever testing or maintenance activities once the instance is detached.
Get started and create your free Blink account today.