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

ComponentPurpose
ListenerChecks for connection requests on a port (80, 443)
Target GroupGroup of targets (ECS tasks) that receive traffic
Health CheckPeriodic request to verify targets are healthy
Listener RulesRoute 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.
ComponentCost (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

ErrorMeaningSolution
502 Bad GatewayTarget returned invalid responseCheck container logs, verify port mapping
503 Service UnavailableNo healthy targetsCheck health check path, container health
504 Gateway TimeoutTarget took too long to respondIncrease timeout, optimize slow endpoints

AWS Deployment Guide — Built with Next.js