ALB
Application Load Balancer
AWS's L7 load balancer. Distributes HTTP/HTTPS traffic based on path and host.
Application Load Balancer
AWS's L7 load balancer. Distributes HTTP/HTTPS traffic based on path and host.
ALB (Application Load Balancer) is an OSI Layer 7 (application layer) load balancer provided by AWS. It understands the content of the HTTP/HTTPS protocols and can perform intelligent traffic routing based on URL paths (/api/*, /images/*), host headers (api.example.com, www.example.com), HTTP methods, query strings, and more.
Announced at AWS re:Invent in 2016, it is replacing the Classic Load Balancer (CLB). A single ALB can host multiple applications, making it optimized for microservice architectures. Through the Target Group concept, it can distribute traffic to various backends such as EC2, ECS, Lambda, and IP addresses.
It natively supports WebSocket and HTTP/2, and also supports the gRPC protocol. By integrating with AWS Certificate Manager (ACM), it automatically renews free SSL/TLS certificates, and by handling HTTPS termination (SSL Termination) at the load balancer, it can reduce the load on backend servers.
In practice, ALB is the most widely used entry point for container-based applications together with ECS Fargate and EKS. Features such as fixed responses, redirects, and authentication (OIDC/Cognito) can be handled at the load balancer level, which simplifies application code.
# ALB + Target Group + Listener 전체 구성
resource "aws_lb" "main" {
name = "my-app-alb"
internal = false
load_balancer_type = "application"
security_groups = [aws_security_group.alb.id]
subnets = aws_subnet.public[*].id
enable_deletion_protection = true
tags = {
Environment = "production"
}
}
# Target Group - ECS/EC2 대상
resource "aws_lb_target_group" "app" {
name = "my-app-tg"
port = 8080
protocol = "HTTP"
vpc_id = aws_vpc.main.id
target_type = "ip" # Fargate의 경우 ip, EC2는 instance
health_check {
enabled = true
healthy_threshold = 2
interval = 30
matcher = "200"
path = "/health"
timeout = 5
unhealthy_threshold = 3
}
}
# HTTPS Listener (443)
resource "aws_lb_listener" "https" {
load_balancer_arn = aws_lb.main.arn
port = "443"
protocol = "HTTPS"
ssl_policy = "ELBSecurityPolicy-TLS13-1-2-2021-06"
certificate_arn = aws_acm_certificate.main.arn
default_action {
type = "forward"
target_group_arn = aws_lb_target_group.app.arn
}
}
# 경로 기반 라우팅 규칙
resource "aws_lb_listener_rule" "api" {
listener_arn = aws_lb_listener.https.arn
priority = 100
action {
type = "forward"
target_group_arn = aws_lb_target_group.api.arn
}
condition {
path_pattern {
values = ["/api/*"]
}
}
}
"If we use path-based routing on the ALB to send /api/* to the backend service and / to the frontend service, we can run multiple services under a single domain. You can also get the SSL certificate for free from ACM and attach it to the ALB."
"To explain the difference between ALB and NLB: ALB parses HTTP content at L7 and routes based on it, while NLB passes TCP/UDP connections through as they are at L4. If you need path-based routing, as with microservices, choose ALB; if you need a game server or high-performance TCP, choose NLB."
"5xx errors have spiked, and looking at the ALB target group health checks, the healthy host count is 0. Let's check the backend container logs and first confirm that the health check path (/health) is responding properly. When a new ECS task starts, it may take a little time to register with the ALB."
Take a mock interview on this topic → WIA SOOM AI Interview · Start for free
In the ALB's Security Group, open only 443 to 0.0.0.0/0, and in the Target's (EC2/ECS) Security Group, allow the ALB Security Group as the source. If you open 0.0.0.0/0 on the Target, direct access that bypasses the ALB becomes possible, creating a security risk.
If the ALB health check path differs from the application's actual health check path, the healthy host count drops to 0 and 503 errors occur. Set the health check interval and threshold values as well, taking the application's startup time into account.
Place subnets in at least 2 Availability Zones (AZs) for the ALB. Enabling Cross-Zone Load Balancing evens out traffic distribution across AZs. In production, be sure to store Access Logs in S3 so that traffic analysis is possible.