Register or De-Register EC2 Instances for Your Load Balancer
Registering an EC2 instance adds it to your load balancer. The load balancer continuously monitors the health of its registered instances, and routes requests to the healthy registered instances. If demand on your instances increases, you can register additional instances with the load balancer to handle the demand.
De-registering an EC2 instance removes it from your load balancer. The load balancer stops routing requests to an instance as soon as it is de-registered. If demand decreases, or you need to service your instances, you can de-register instances from the load balancer. A de-registered instance remains running, but no longer receives traffic from the load balancer, and you can register it with the load balancer again when you are ready.
When you de-register an instance, Elastic Load Balancing waits until in-flight requests have completed if connection draining is enabled. For more information, see Configure Connection Draining for Your Load Balancer.
If your load balancer is attached to an Auto Scaling group, instances in the group are automatically registered with the load balancer. If you detach a load balancer from your Auto Scaling group, the instances in the group are de-registered.
Elastic Load Balancing registers your EC2 instance with your load balancer using its IP address.
[EC2-VPC] When you register an instance with an elastic network interface (ENI) attached, the load balancer routes requests to the primary IP address of the primary interface (eth0) of the instance.
Register an Instance
When you are ready, register your instance with your load balancer.
The instance must be a running instance in the same network as the load balancer (EC2-Classic or the same VPC). If you have EC2-Classic instances and a load balancer in a VPC with ClassicLink enabled, you can link the EC2-Classic instances to that VPC and then register them with a load balancer in the VPC.
To register your back-end instances using the console
Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.
In the navigation pane, under LOAD BALANCING, click Load Balancers.
Select your load balancer.
In the bottom pane, select the Instances tab.
Click Edit Instances.
Select the instance to register with your load balancer.
Click Save.
To register your back-end instance using the AWS CLI
Use the following register-instances-with-load-balancer command:
aws elb register-instances-with-load-balancer --load-balancer-name my-loadbalancer --instances i-4e05f721The following is an example response that lists the instances registered with the load balancer:
{
"Instances": [
{
"InstanceId": "i-315b7e51"
},
{
"InstanceId": "i-4e05f721"
}
]
}De-register an Instance
You can de-register a back-end instance from your load balancer if you no longer need the capacity or if you need to service the instance.
If your load balancer is attached to an Auto Scaling group, detaching the instance from the group also de-registers it from the load balancer. For more information, see Detach EC2 Instances From Your Auto Scaling Group in the Auto Scaling Developer Guide.
To de-register your back-end instances using the console
Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.
In the navigation pane, under LOAD BALANCING, click Load Balancers.
Select your load balancer.
In the bottom pane, select the Instances tab.
In Actions column for the instance to de-register, click Remove from Load Balancer.
When prompted for confirmation, click Yes, Remove.
To de-register your back-end instances using the AWS CLI
Use the following deregister-instances-from-load-balancer command:
aws elb deregister-instances-from-load-balancer --load-balancer-name my-loadbalancer --instances i-4e05f721The following is an example response that lists the remaining instances registered with the load balancer:
{
"Instances": [
{
"InstanceId": "i-315b7e51"
}
]
}