Debug AWS Application Load Balancer (ALB) 502, 503 & 504 Errors Visually
Application Load Balancer errors (HTTP 502, 503, 504) are among the top production incidents and AWS interview troubleshooting questions. CloudTracer simulates Layer 7 ALB reverse-proxying, target group health checks, and least-privilege Security Group chaining.
503 Service Unavailable
Usually means zero healthy targets in the Target Group — check health check path, port, or EC2 Security Group ingress from the ALB SG.
504 Gateway Timeout
ALB cannot reach the backend EC2 instance or the backend timed out — check Security Group egress/ingress and NACL return rules.
Least-Privilege SG Chaining
Best practice: allow 0.0.0.0/0 -> TCP:443 on the ALB SG, and restrict the EC2 SG inbound strictly to the ALB Security Group ID.
AWS ALB Error Code Quick Diagnostic Matrix
| Step / Dimension | Component | Technical Behavior |
|---|---|---|
| HTTP 502 Bad Gateway | Malformed Backend Response | Target closed connection prematurely or returned invalid HTTP headers to the ALB. |
| HTTP 503 Unavailable | Zero Healthy Targets | All registered EC2/ECS targets failed health checks or Target Group is empty. |
| HTTP 504 Timeout | Blocked Network Path / Slow App | EC2 Security Group blocks ALB traffic, NACL drops return packets, or idle timeout exceeded. |
| Cross-AZ Failure | Single-AZ Subnet Mapping | ALB requires at least two public subnets in different Availability Zones for high availability. |
Terraform Least-Privilege ALB-to-EC2 Security Group Rule
resource "aws_security_group_rule" "ec2_from_alb" {
type = "ingress"
from_port = 80
to_port = 80
protocol = "tcp"
security_group_id = aws_security_group.ec2_app.id
source_security_group_id = aws_security_group.alb_public.id
}
Frequently Asked Questions
Why is my AWS ALB returning 503 Service Unavailable?
A 503 from an ALB almost always means the Target Group has zero healthy registered targets. Verify your health check path returns HTTP 200 and that the EC2 Security Group allows health check traffic from the ALB Security Group.
How should I configure Security Groups between an ALB and EC2?
Attach an internet-facing Security Group (allowing TCP 80/443 from 0.0.0.0/0) to the ALB, and configure the EC2 Security Group to accept traffic ONLY from the ALB Security Group ID.
Does CloudTracer simulate ALB health checks and Layer 7 routing?
Yes. CloudTracer evaluates target group health status, weighted routing, and cross-AZ failover during live packet simulation.