Prepare to attach an Elastic Load Balancing load balancer
Before you attach an Elastic Load Balancing load balancer to your Auto Scaling group, you must complete the following prerequisites:
-
You must have already created the load balancer and target group that is used to route traffic to your Auto Scaling group.
There are two ways to create the load balancer and target group:
-
Using Elastic Load Balancing – Follow the procedures in the Elastic Load Balancing documentation to create and configure the load balancer and target group before creating the Auto Scaling group. Skip the step for registering your Amazon EC2 instances. Amazon EC2 Auto Scaling automatically takes care of registering (and deregistering) instances when you attach a target group to your Auto Scaling group. For more information, see Getting started with Elastic Load Balancing in the Elastic Load Balancing User Guide.
-
Using Amazon EC2 Auto Scaling – Create, configure, and attach the load balancer and target group with a basic configuration from the Amazon EC2 Auto Scaling console. For more information, see Configure an Application Load Balancer or Network Load Balancer from the console.
-
-
Before creating a load balancer, know the type of load balancer that you need. For more information, see Elastic Load Balancing types.
-
The load balancer and its target group must be in the same AWS account, VPC, and Region as your Auto Scaling group.
-
The target group must specify a target type of
instance
. You can't specify a target type ofip
when using an Auto Scaling group. -
If the launch template for your Auto Scaling group does not contain the correct security group to allow the necessary inbound traffic from the load balancer, you must update the launch template. The recommended rules depend on the type of load balancer and the types of backends that the load balancer uses. For example, to route traffic to web servers, allow inbound HTTP access on port 80 from the load balancer. Existing instances are not updated with the new settings when the launch template is modified. To update existing instances, you can start an instance refresh to replace the instances. For more information, see Use an instance refresh to update instances in an Auto Scaling group.
-
The security groups in the launch template must also allow access from the load balancer on the correct port for Elastic Load Balancing to perform its health checks.
-
When deploying virtual appliances behind a Gateway Load Balancer, the Amazon Machine Image (AMI) in the launch template must specify the ID of an AMI that supports the GENEVE protocol to allow the Auto Scaling group to exchange traffic with a Gateway Load Balancer. Also, the security groups in the launch template must allow UDP traffic on port 6081.
Tip
If you have bootstrapping scripts that take a while to complete, you can optionally add a launch lifecycle hook to your Auto Scaling group to delay instances from registering behind the load balancer before your bootstrap scripts have completed successfully and the applications on the instances are ready to accept traffic. You can't add a lifecycle hook when you initially create an Auto Scaling group in the Amazon EC2 Auto Scaling console. However, you can add a lifecycle hook after the group is created. For more information, see Amazon EC2 Auto Scaling lifecycle hooks.
Configure health checks for targets
You can configure health checks for your targets registered with an Elastic Load Balancing load balancer to ensure they are able to handle traffic properly. The specific steps vary based on the type of load balancer you are using. For more information, see the following resources:
-
Application Load Balancer – See Health checks for your target groups in the User Guide for Application Load Balancers.
-
Network Load Balancer – See Health checks for your target groups in the User Guide for Network Load Balancers.
-
Gateway Load Balancer – See Health checks for your target groups in the User Guide for Gateway Load Balancers.
-
Classic Load Balancer – See Configure health checks for your Classic Load Balancer in the User Guide for Classic Load Balancers.
By default, Amazon EC2 Auto Scaling does not consider an instance unhealthy and replace it if it fails the Elastic Load Balancing health checks. The default health checks for an Auto Scaling group are EC2 health checks only. For more information, see Health checks for instances in an Auto Scaling group.
To enable Amazon EC2 Auto Scaling to replace instances that are reported unhealthy by Elastic Load Balancing, you can configure your Auto Scaling group to use Elastic Load Balancing health checks. By doing so, Amazon EC2 Auto Scaling considers the instance unhealthy if it fails either the EC2 health checks or the Elastic Load Balancing health checks. If you attach multiple load balancer target groups or Classic Load Balancers to the group, all of them must report that an instance is healthy in order for it to consider the instance healthy. If any one of them reports an instance as unhealthy, the Auto Scaling group replaces the instance, even if others report it as healthy.
For information about how to enable these health checks for your Auto Scaling group, see Attach an Elastic Load Balancing load balancer to your Auto Scaling group.
Note
To make sure that these health checks start as soon as possible, make sure your group's health check grace period is not set too high, but high enough for your Elastic Load Balancing health checks to determine whether a target is available to handle requests. For more information, see Set the health check grace period for an Auto Scaling group.