AWS Elastic Load Balancing health checks serve as the mechanism by which a load balancer evaluates the availability and responsiveness of its registered targets. Without a correctly configured health check, traffic can be routed to instances that are unhealthy, leading to application errors and a poor user experience. The health check operates by periodically sending requests to a specific port and path on your registered targets, analyzing the response to determine if the endpoint is operational. A target is considered healthy only when it meets the criteria defined in the health check configuration, allowing the load balancer to send requests to it.
Understanding Health Check Parameters
Configuring AWS ELB health checks requires understanding several key parameters that define the behavior of the evaluation process. These settings provide granular control over how the load balancer determines the health state of your backend resources. Adjusting these values allows you to balance between rapid failure detection and system overhead. The primary parameters include the protocol, port, path, healthy threshold, unhealthy threshold, timeout, and interval.
Protocol, Port, and Path Configuration
The protocol defines the method used to check the target, typically HTTP, HTTPS, or TCP. For HTTP and HTTPS checks, you specify a path, such as `/health.html`, which the load balancer requests to validate functionality. The port parameter indicates where the check is sent, which can be the standard HTTP port 80 or a custom port your application listens on. Using a dedicated, lightweight endpoint for health checks is a best practice, as it ensures the check validates the load balancer's ability to reach the application logic without incurring the overhead of full page rendering or database queries.
Thresholds and Timing Parameters
The healthy and unhealthy thresholds determine how consecutive successes or failures are counted before a state change occurs. For example, if the healthy threshold is set to 2, the target must pass two consecutive checks before being marked as healthy again. Conversely, the unhealthy threshold dictates how many failed checks trigger a deregistration event. The timeout setting defines how long the load balancer waits for a response before marking the check as failed, while the interval sets the frequency of the checks. Optimizing these values is critical; setting them too aggressively can cause the system to react to transient network blips, while setting them too loosely can result in prolonged outages going unnoticed.
Health Check Response Codes
For HTTP and HTTPS health checks, the expected response codes are a critical part of the configuration. By default, a target is considered healthy if it returns a success code of 200. However, applications often return specific codes to indicate different states, such as 200 for OK, 404 for not found, or 500 for server error. You can configure the load balancer to accept a list of success codes, allowing flexibility for APIs that return 200 for standard operations and 201 for successful resource creation. Ensuring the health check code matches the actual response code from your application is essential for accurate status reporting.
TCP and Classic Load Balancer Checks
When using TCP health checks, the process is simpler and less application-specific. The load balancer attempts to open a TCP connection to the target on the specified port. If the connection is successful, the target is considered healthy, regardless of the application layer logic. This method is useful for non-HTTP applications or databases where a TCP handshake is sufficient to determine availability. For Classic Load Balancers, the configuration follows a similar pattern but is managed through the older EC2-Classic dashboard, requiring careful attention to security group settings to ensure the balancer can reach the target port.