In Amazon Web Services (AWS), the Elastic Load Balancing (ELB) service automatically distributes incoming application traffic across multiple targets, such as Amazon EC2 instances, containers, and IP addresses, in one or more Availability Zones. These targets are grouped into "Target Groups."
One of the key features of the Elastic Load Balancer, especially the Application Load Balancer (ALB) and Network Load Balancer (NLB), is the ability to perform health checks on the targets in these groups. This ensures that traffic is only sent to healthy targets, which improves the reliability and fault tolerance of your applications.
Health Checks for Target Groups:
Purpose: Health checks are used to determine the health of the targets. If a target fails a health check, it's considered "unhealthy" and won't receive any traffic until it becomes "healthy" again.
Configuration:
Protocol & Port: Determines how the load balancer routes health check requests to the targets (e.g., HTTP, HTTPS, TCP).
Ping Path (for HTTP/HTTPS): The destination for the health check request (e.g., "/health" or "/ping").
Interval: The time duration between health checks.
Timeout: The amount of time to wait when receiving a response from the health check.
Unhealthy Threshold: The number of consecutive failures before marking the target as unhealthy.
Healthy Threshold: The number of consecutive successful health checks required to mark an unhealthy target as healthy again.
Behavior:
If a target is found to be unhealthy (i.e., it fails the health check the specified number of times), the ELB will stop routing traffic to that target until it becomes healthy again.
Conversely, if a previously unhealthy target passes the health check the specified number of times, it's marked as healthy, and traffic starts getting routed to it again.
Response Codes: For HTTP/HTTPS health checks, you can specify the HTTP response codes that should be considered a pass. Typically, this includes 200-level (success) codes.
Traffic Routing: ELB uses the health check status of each target to determine where to route the traffic. Targets with a healthy status receive requests, while those with an unhealthy status don't.
Lambda Targets: If you're using Lambda functions as targets for your ALB, the ALB will invoke the function with the health check request. Your function must return a 200 response for the ALB to consider it healthy.
Target health status:
Before the load balancer sends a health check request to a target, you must register it with a target group, specify its target group in a listener rule, and ensure that the Availability Zone of the target is enabled for the load balancer.
The following table describes the possible values for the health status of a registered target.
Value | Description |
initial | The load balancer is in the process of registering the target or performing the initial health checks on the target. |
healthy | The target is healthy. |
unhealthy | The target did not respond to a health check or failed the health check. |
unused | The target is not registered with a target group, the target group is not used in a listener rule, the target is in an Availability Zone that is not enabled, or the target is in the stopped or terminated state. |
draining | The target is deregistering and connection draining is in process. |
unavailable | Target health is unavailable. |
Best Practices:
Ensure your targets respond promptly to health check requests. This helps ELB to quickly identify and route traffic away from unhealthy targets.
Use meaningful paths for health checks. For instance, if your service has a "/health" endpoint that checks database connectivity and other critical components, use that for health checks.
Adjust the health check settings based on the nature of your application. Some applications might require tighter intervals and thresholds than others.
Health checks in AWS ELB play a pivotal role in ensuring high availability and fault tolerance for your applications by intelligently routing traffic to healthy targets. Properly configuring and understanding health checks can significantly improve the user experience of your applications by minimizing downtime and reducing the chances of users encountering errors.
Check the health of your targets:
You can check the health status of the targets registered with your target groups.
To check the health of your targets using the new console
Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.
In the navigation pane, under LOAD BALANCING, choose Target Groups.
Choose the name of the target group to open its details page.
The Details pane displays the total number of targets, plus the number of targets for each health status.
On the Targets tab, the Health status column indicates the status of each target.
If the status of a target is any value other than
Healthy
, the Health status details column contains more information.