Troubleshooting Load Balancer Errors
This lesson explains how the status code, and whether it came from the load balancer or the target, tell you where to look when users receive HTTP errors.
Learning outcomes
After completing this lesson, you will be able to:
- Separate load balancer errors from target errors with metrics.
- Identify the causes of ALB 502, 503 and 504 errors.
- Resolve other common issues such as uneven load.
Load balancer or target?
ALB metrics separate errors generated by the load balancer (HTTPCode_ELB_4XX_Count, HTTPCode_ELB_5XX_Count) from responses returned by targets (HTTPCode_Target_4XX_Count, HTTPCode_Target_5XX_Count). A target 5XX means the application returned the error; an ELB 5XX means the load balancer could not get a valid response. Access logs, stored in S3 when enabled, contain both elb_status_code and target_status_code (a dash when the target did not respond), plus request_processing_time, target_processing_time and response_processing_time. Connection logs record TLS handshake details, and health check logs record each check.
The following diagram shows which side generates each kind of error.

Load balancer error codes
The following table lists the ALB-generated errors and their usual causes.
| Code | Meaning | Usual cause |
|---|---|---|
| 502 Bad Gateway | Invalid response from target | Target closed the connection, malformed response, Lambda error or response too large, keep-alive timeout on the target shorter than the ALB idle timeout |
| 503 Service Unavailable | No registered healthy targets | Empty target group or all targets in unused AZs |
| 504 Gateway Timeout | Target did not respond within the idle timeout | Slow application, idle timeout too short, or security group/NACL dropping traffic to the target |
| 460 | Client closed connection before the response | Client timeout shorter than the processing time |
| 463 | X-Forwarded-For header with too many IPs | Proxy chain misconfiguration |
| 4XX from ELB (400, 403) | Malformed request or WAF block | Check WAF logs for 403 |
ALB error codes
Other common issues
Several other issues appear regularly. The following list describes them.
- Uneven load: cross-zone load balancing off on an NLB with unequal targets per AZ, or sticky sessions concentrating users.
- Client IP missing in application logs: an ALB passes it in the
X-Forwarded-Forheader; NLBs preserve it at the IP level (or with proxy protocol v2). - Users logged out after scale-in: sessions stored locally; use ElastiCache or DynamoDB, or stickiness as a short-term fix.
- Long-running requests cut off: the idle timeout (60 seconds by default) is shorter than the request.
- Requests fail during deployments: deregistration delay too short for in-flight requests.
60s
Default idle timeout
Load balancer symptoms
Intermittent 502 errors
An ALB reports a small but steady rate of HTTPCode_ELB_502_Count while target 5XX counts are zero. Access logs show the 502 requests have target_status_code of - and very short processing times, and they occur on connections that had been idle for about 5 seconds. The targets run a web server with a keep-alive timeout of 5 seconds, while the ALB's idle timeout is 60 seconds, so the server sometimes closes a connection at the moment the ALB reuses it. Setting the web server's keep-alive timeout above the ALB idle timeout, to 65 seconds, eliminates the errors.
What does a 503 from an Application Load Balancer usually mean?
Show answer
There are no healthy targets in the target group.
Exam Tips
Remember for the exam
- HTTPCode_ELB_5XX is the load balancer; HTTPCode_Target_5XX is the application.
- 502: bad or closed target response; 503: no healthy targets; 504: target too slow.
- Set target keep-alive timeouts longer than the ALB idle timeout.
- Access logs show elb_status_code, target_status_code and processing times.
- ALBs pass the client IP in X-Forwarded-For.