Interview Prep/AWS/EC2, Auto Scaling and Load Balancing

ALB returns `504 Gateway Timeout` on a report endpoint.

IntermediateTroubleshootingEC2, Auto Scaling and Load Balancing
Answer

Likely causes → The target did not respond before the ALB idle timeout (60s by default). Either the request is too slow, or the target is unreachable (blocked by an SG or NACL), so the connection attempt times out.

Diagnose →

aws elbv2 describe-load-balancer-attributes --load-balancer-arn <alb-arn> \
  --query "Attributes[?Key=='idle_timeout.timeout_seconds']"
# access logs: high target_processing_time, or request_processing_time -1
aws cloudwatch get-metric-statistics --namespace AWS/ApplicationELB --metric-name TargetResponseTime \
  --dimensions Name=LoadBalancer,Value=app/web/abc123 --extended-statistics p99 --period 60 \
  --start-time $(date -u -d '-1 hour' +%FT%TZ) --end-time $(date -u +%FT%TZ)

Fix →

  1. As a short-term fix, raise the idle timeout: aws elbv2 modify-load-balancer-attributes --load-balancer-arn <arn> --attributes Key=idle_timeout.timeout_seconds,Value=180
  2. As the real fix, make long jobs asynchronous: return 202, process through a queue, and let the client poll or receive a webhook

Prevent → Track TargetResponseTime p99 per route, and keep synchronous requests well under the timeout.

aws All AWS questions Roadmap: AWS core services

More on EC2, Auto Scaling and Load Balancing