Application Load Balancer
Distribute traffic and enable HTTPS for your application
šµ Cost: ALB has a fixed hourly cost ~$16/month plus capacity charges. This runs 24/7 once created! Delete ALB when not in use to avoid charges. See our Costs & Cleanup Guide.
What is an ALB?
An Application Load Balancer (ALB) distributes incoming HTTP/HTTPS traffic across multiple targets (like ECS tasks). It operates at Layer 7 (application layer), meaning it understands HTTP and can make routing decisions based on URLs, headers, and more.
Why Use an ALB?
- Distribute traffic across multiple containers for reliability
- Terminate SSL/TLS (HTTPS) at the load balancer
- Health checks automatically remove unhealthy targets
- Path-based routing: /api/* to one service, /* to another
ALB Components
Plain Text
Internet
ā
ā¼
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā Application Load Balancer ā
ā āāā Listener (port 443, HTTPS) ā
ā ā āāā SSL Certificate ā
ā ā ā
ā āāā Listener (port 80, HTTP) ā
ā āāā Redirect to HTTPS ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā
ā¼
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā Target Group ā
ā āāā Health Check: /api/health ā
ā āāā Target: ECS Task 1 (10.0.1.5) ā
ā āāā Target: ECS Task 2 (10.0.1.6) ā
ā āāā Target: ECS Task 3 (10.0.1.7) ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāKey Concepts
| Component | Purpose |
|---|---|
| Listener | Checks for connection requests on a port (80, 443) |
| Target Group | Group of targets (ECS tasks) that receive traffic |
| Health Check | Periodic request to verify targets are healthy |
| Listener Rules | Route traffic based on path, host, headers, etc. |
The ALB periodically checks if your containers are healthy. Unhealthy containers are removed from rotation until they recover.
TypeScript
// app/api/health/route.ts
export async function GET() {
// Check database connection, external services, etc.
try {
// await prisma.$queryRaw`SELECT 1`
return Response.json({ status: "healthy" })
} catch (error) {
return Response.json(
{ status: "unhealthy", error: "Database connection failed" },
{ status: 503 }
)
}
}Health Check Settings
Default health check settings might be too aggressive. Consider:
- Interval: 30 seconds (not 5 seconds)
- Timeout: 10 seconds
- Healthy threshold: 2 consecutive successes
- Unhealthy threshold: 3 consecutive failures
ALB Pricing
Region-Specific Pricing
Prices shown are for ap-southeast-1 (Singapore). Prices vary by region. Always verify at aws.amazon.com/elasticloadbalancing/pricing. Last verified: January 2026.
| Component | Cost (ap-southeast-1) |
|---|---|
| ALB per hour | ~$0.0225/hour (~$16/month) |
| LCU (Load Balancer Capacity Unit) | ~$0.008/LCU-hour |
Cost Tip
For small applications, the fixed hourly cost dominates. The ALB itself costs about $16-20/month regardless of traffic. LCU charges only matter at higher traffic volumes.
Common ALB Errors
| Error | Meaning | Solution |
|---|---|---|
502 Bad Gateway | Target returned invalid response | Check container logs, verify port mapping |
503 Service Unavailable | No healthy targets | Check health check path, container health |
504 Gateway Timeout | Target took too long to respond | Increase timeout, optimize slow endpoints |