High Availability (HA) means running your application in at least two data centers (== AZ). The goal of HA is to survive a data center loss.
Load balancers (LB) are servers that forward internet traffic to multiple servers (EC2 instances) downstream.
Uses of LB
The health check is done through port and route (/health
is a common one)
200
, that instance would be deemed unhealthyClassic LB (v1, 2009)
XXX.region.elb.amazonaws.com
Application LB (v2, 2016)
Supports layer 7 - HTTP, HTTPS
The default routing algorithm is round robin
Supports path based routing (wildcard supported)
Fixed hostname (XXX.region.elb.amazonaws.com
)
The application servers don't see IP of client directly — use X-Forwarded-For
header
Load balancing to multiple apps on the same machine (containers)
Supports HTTP/2 , websockets and redirects
Routing based on different paths e.g. /user
and /posts
Routing based on hostname in URL and query strings
Routing based on HTTP headers and methods
Cross-zone load balancing is ALWAYS enabled
The targets can be lambdas as well
Need detailed HTTP logs → Enable access logs
You are charged for each hour (full or partial) that an ALB is running and the number of Load Balancer Capacity Units (LCU) used per hour.
You are not charged for cross-region data transfer while load balancing
Great for microservices and containers (targets in general)
(Setup video = #78)
Network LB (new v2, 2017)
It's recommended to use newer versions.
Any user can talk to ELB but only ELB can talk to EC2. The EC2 instance's security group should be configured such that it can only talk to the ELB.
ELBs can scale but not instantaneously, contact AWS for a warmup
ELB access logs will log all requests (CloudWatch)