Overview
An Application Load Balancer (ALB) operates at Layer 7 and distributes HTTP/HTTPS traffic across a Target Group of registered instances. When integrated with an ASG, instances register and deregister automatically โ and ALB health checks drive ASG instance replacement when an application (not just the VM) is unhealthy.
Why It Matters
EC2 health checks only detect VM-level failure. An instance can be running and passing EC2 checks while the application inside is broken. ELB health checks detect application-level failure โ and when wired to an ASG, trigger automatic replacement. This is the difference between infrastructure self-healing and application self-healing.
Where It Fits
DOP-C02 Domain 3 โ Resilient Cloud Solutions
Internet | v ALB (Layer 7) | v Listener :80/:443 | v Listener Rules (path/host routing) | v Target Group | +– Health Check (:80, GET /, expect 200) | +– Instance 1 (ASG-managed) +– Instance 2 (ASG-managed)
The Big Picture
HAProxy AWS Equivalent
frontend (bind *:80) โ ALB Listener acl / use_backend โ Listener Rules backend โ Target Group server (health check) โ Target Group Health Check balance roundrobin โ ALB default routing
ALB is managed HAProxy โ same mental model, AWS operates the infrastructure.
Core Concepts
Load Balancer Types โ pick the right one:
ALBโ Layer 7, HTTP/HTTPS, path and host-based routing โ default exam answer for web trafficNLBโ Layer 4, TCP/UDP, static IPs, TLS passthrough, ultra-low latencyGLBโ Layer 3, routes traffic through third-party security appliances (firewalls, IDS)
ALB requires two subnets in different AZs โ single-AZ ALB is not supported. Always pass at least two public subnets on creation.
Target Group โ the backend pool. Health check config lives here, not on the ALB. Targets can be EC2 instances, IP addresses, Lambda functions, or another ALB.
Health check fields that matter:
HealthCheckPathโ what URL the ALB hits (equivalent to HAProxyoption httpchk)HealthyThresholdCountโ consecutive successes before marking healthy (lab: 2)UnhealthyThresholdCountโ consecutive failures before marking unhealthy (lab: 2)Matcher.HttpCodeโ expected response code (default: 200)
ELB health check type on ASG โ switches ASG from EC2 checks to ALB checks. When the Target Group marks an instance unhealthy, ASG terminates and replaces it.
Health check grace period โ how long ASG waits after launch before starting ELB health checks. Set this longer than your bootstrap time or ASG will terminate instances before they finish starting.
Real-World Example
Full stack built via CLI in devopslab-vpc:
Resources created:
- ALB
dop-lab-albโ internet-facing, subnets 1a + 1b, security groupdop-lab-sg - Target Group
dop-lab-tgโ HTTP:80, health checkGET /expect 200, thresholds 2/2 - Listener โ HTTP:80 โ forward to
dop-lab-tg - ASG updated โ health-check-type ELB, grace period 60s, desired=2
Verified:
- Single instance registered healthy in target group
- Scaled to desired=2 โ second instance auto-registered
watch -n2 curlconfirmed ALB round-robining betweenip-10-50-1-86andip-10-50-1-203
Teardown order (dependency-first):
- Delete Listener
- Delete ALB
- Delete Target Group
- Scale ASG to 0/0/0
ALB + ASG Build Runbook
# 1. Create ALB (requires 2 subnets in different AZs)
aws elbv2 create-load-balancer \
--name <alb-name> \
--subnets <subnet-1a> <subnet-1b> \
--security-groups <sg-id> \
--scheme internet-facing \
--type application
# 2. Create Target Group
aws elbv2 create-target-group \
--name <tg-name> \
--protocol HTTP --port 80 \
--vpc-id <vpc-id> \
--health-check-path / \
--health-check-interval-seconds 30 \
--healthy-threshold-count 2 \
--unhealthy-threshold-count 2
# 3. Create Listener
aws elbv2 create-listener \
--load-balancer-arn <alb-arn> \
--protocol HTTP --port 80 \
--default-actions Type=forward,TargetGroupArn=<tg-arn>
# 4. Attach Target Group to ASG
aws autoscaling attach-load-balancer-target-groups \
--auto-scaling-group-name <asg-name> \
--target-group-arns <tg-arn>
# 5. Switch ASG to ELB health checks
aws autoscaling update-auto-scaling-group \
--auto-scaling-group-name <asg-name> \
--health-check-type ELB \
--health-check-grace-period 60
# 6. Verify target health
aws elbv2 describe-target-health \
--target-group-arn <tg-arn> \
--output table
# Teardown (billing stops when ALB is deleted)
aws elbv2 delete-listener --listener-arn <listener-arn>
aws elbv2 delete-load-balancer --load-balancer-arn <alb-arn>
aws elbv2 delete-target-group --target-group-arn <tg-arn>
aws autoscaling update-auto-scaling-group \
--auto-scaling-group-name <asg-name> \
--min-size 0 --max-size 0 --desired-capacity 0
Engineering Analogy
Your HAProxy config has a frontend binding a port, acl rules routing to named backend blocks, each with server lines and option httpchk. ALB is that exact architecture โ Listener = frontend, Rules = acl/use_backend, Target Group = backend, health check = httpchk. The difference is AWS manages the proxy infrastructure and integrates it with ASG so backends register and deregister automatically.
Best Practices
- Always set
--health-check-grace-periodlonger than your slowest bootstrap โ premature ELB checks terminate healthy instances mid-startup - Use
describe-target-healthto confirm registration before testing traffic - Teardown listener before ALB โ dependency order prevents API errors
- Use path-based routing rules for microservices (
/api/*โ TG-A,/web/*โ TG-B) rather than separate ALBs per service
Common Mistakes
- Creating ALB with only one subnet โ fails immediately, ALB requires multi-AZ
- Forgetting to switch ASG health check type to ELB โ ASG keeps using EC2 checks only, app failures don’t trigger replacement
- Grace period too short โ ASG terminates instances that are still bootstrapping
- Leaving ALB running after a lab โ unlike EC2, ALB bills by the hour even with zero targets
Pro Tip
describe-target-healthis your first debugging tool when traffic isn’t reaching instances. Check State (initial,healthy,unhealthy) and the Description field โ it tells you exactly why a target failed health checks (connection refused, timeout, wrong HTTP code).
Key Takeaways
- ALB = managed HAProxy โ same mental model, AWS operates the infrastructure
- Target Groups hold health check config โ not the ALB itself
- ELB health check type on ASG is what enables application-level self-healing, not just VM-level
- ALB requires two subnets in different AZs โ single-AZ is not supported
- Teardown order matters: Listener โ ALB โ Target Group โ ASG scale-down
Related Articles
- DevOpsPro-AWS-Auto-Scaling-Groups-The-Self-Healing-Control-Loop.md
- DevOpsPro-ASG-Lifecycle-Hooks-Pending-Wait-and-Bootstrap-Control.md
References
- AWS Documentation: Application Load Balancers
- AWS Documentation: Target Groups for your Application Load Balancers
- Live lab performed in devopslab-vpc, account 046685909731, 2026-08-08