ELB & Auto Scaling Groups

Pick the right load balancer for the OSI layer and target type; wrap the fleet in an ASG that scales on the right signal.

Chọn load balancer đúng OSI layer & target type; bọc fleet trong ASG scale theo signal đúng.

ALB · NLB · CLB · GWLB — one glanceALB · NLB · CLB · GWLB — bảng nhìn nhanh

ALB NLB CLB GWLB
OSIOSI L7 L4 L4/7 L3
ProtocolsProtocol HTTP · HTTPS · HTTP/2 · WS TCP · UDP · TLS HTTP · HTTPS · TCP GENEVE
TargetsTarget EC2 · IP · ECS · Lambda EC2 · IP · ALB EC2 only EC2 · IP
Public / PrivatePublic / Private Both Both Both Private only
mTLS ✅ HTTPS listener ❌ ❌ pass-through ❌
SNI · multi-cert ✅ ✅ TLS + SNI ❌ ❌
Cross-zoneCross-zone On · free · per-TG offBật · miễn phí · tắt per TG Off · inter-AZ $Tắt · inter-AZ $ Off (API) · freeTắt (API) · miễn phí Off · inter-AZ $Tắt · inter-AZ $
Sticky sessionsSticky ✅ ✅ source IP · not TLS✅ source IP · không TLS ✅ ❌
When each fitsKhi nào dùng ALB for microservices & container platforms. NLB for extreme TCP/UDP throughput and static IP whitelisting. GWLB when a security team says "put a firewall appliance in the traffic path." Need static IP + L7 rules → NLB with an ALB target group behind it — classic SAP answer. ALB cho microservice & container. NLB cho TCP/UDP throughput cực cao và whitelist IP tĩnh. GWLB khi security team yêu cầu "chèn firewall vào đường traffic." Cần IP tĩnh + L7 rules → NLB đứng trước ALB target group — đáp án SAP kinh điển.

GWLB — putting a firewall between VPCsGWLB — chèn firewall vào giữa các VPC

GWLB is a bump in the wire: it doesn't terminate anything, it hands each packet (wrapped in GENEVE, UDP 6081) to an appliance and takes it back unchanged. The GWLB endpoint is what route tables point at. HA = appliances in 2 AZs in one target group + health checks; symmetry = appliance mode on the TGW attachment. GWLB là "cục chèn trên dây": không kết thúc kết nối nào, chỉ đưa từng gói (bọc trong GENEVE, UDP 6081) cho appliance rồi nhận lại nguyên vẹn. GWLB endpoint là thứ mà route table trỏ tới. HA = appliance ở 2 AZ trong cùng một target group + health check; đối xứng = bật appliance mode trên TGW attachment.

Centralised inspection with a Gateway Load Balancer. Spoke VPC A and spoke VPC B both attach to a Transit Gateway that has appliance mode turned on. The Transit Gateway sends traffic into an inspection VPC that spans two Availability Zones. In each zone, the Transit Gateway attachment subnet routes to a GWLB endpoint, the endpoint sends to the Gateway Load Balancer, and the load balancer forwards to a firewall appliance in that zone over GENEVE on UDP port 6081. The appliance returns the packet the same way, back through the Transit Gateway to VPC B. The target group holds one appliance in each zone, with health checks and cross-zone load balancing, so if one appliance fails new flows go to the other. Spoke VPC A 10.1.0.0/16 Spoke VPC B 10.2.0.0/16 Transit Gateway appliance mode ON A → B Inspection VPC · security account AZ-a · this flow TGW attach. subnet GWLB endpoint firewall appliance AZ-b · other flows / failover TGW attach. subnet GWLB endpoint firewall appliance GWLB L3 both AZs GENEVE 6081 target group 2 AZ spoke VPC RT: 0.0.0.0/0 → TGW · TGW-attachment subnet RT: 0.0.0.0/0 → GWLB endpoint GWLB-endpoint subnet RT: 10.0.0.0/8 → TGW · the appliance sends every packet back the way it came

Follow one flow A → B: spoke route table sends it to the TGW; the TGW drops it into the inspection VPC's AZ-a attachment subnet; that subnet's route table points at the GWLB endpoint; GWLB picks the appliance and tunnels the packet to it; the approved packet comes back the same way and the endpoint subnet's route table sends it back to the TGW, which delivers it to VPC B.

Theo một flow A → B: route table của spoke gửi nó tới TGW; TGW thả vào attachment subnet ở AZ-a của inspection VPC; route table subnet đó trỏ tới GWLB endpoint; GWLB chọn appliance và đóng gói gửi tới; gói được duyệt quay về đúng đường cũ, rồi route table của subnet endpoint đẩy nó lại TGW để giao tới VPC B.

  • Why each piece. GWLB = spreads flows over appliances and keeps each flow on the same one (stickiness). GWLB endpoint = a PrivateLink endpoint you can use as a route target — it can live in another account's VPC, so a security account owns GWLB + appliances and spokes only create endpoints. Target group in 2 AZs = no single appliance or AZ takes the network down. Vì sao cần từng mảnh. GWLB = chia flow cho các appliance và giữ mỗi flow ở nguyên một appliance (stickiness). GWLB endpoint = một PrivateLink endpoint dùng được làm route target — nó nằm được ở VPC của account khác, nên account security sở hữu GWLB + appliance, còn các spoke chỉ tạo endpoint. Target group ở 2 AZ = không có appliance hay AZ nào là điểm chết của cả mạng.
  • Appliance mode on the TGW attachment pins both directions of a flow to the same AZ. Without it, the reply can enter through AZ-b, hit an appliance that never saw the SYN, and a stateful firewall drops it. Appliance mode trên TGW attachment giữ cả hai chiều của một flow ở cùng một AZ. Không bật thì gói trả lời có thể vào qua AZ-b, tới appliance chưa từng thấy gói SYN, và firewall stateful sẽ drop.
  • Failover. Health checks mark a dead appliance unhealthy. With cross-zone load balancing on (off by default for GWLB), AZ-a's endpoint can send new flows to the appliance in AZ-b; existing flows are rebalanced only if you enable target failover. Failover. Health check đánh dấu appliance chết là unhealthy. Khi bật cross-zone load balancing (GWLB mặc định tắt), endpoint ở AZ-a mới gửi được flow mới sang appliance ở AZ-b; flow đang chạy chỉ được chuyển nếu bật target failover.
  • Two shapes. Centralised (above): one inspection VPC behind a TGW for east-west and egress. Distributed: a GWLB endpoint in each VPC, with an IGW ingress route table (edge association) to inspect internet ingress before it reaches the subnets. Hai kiểu triển khai. Tập trung (như hình): một inspection VPC sau TGW cho traffic east-west và egress. Phân tán: GWLB endpoint trong từng VPC, kèm ingress route table của IGW (edge association) để soi traffic từ Internet trước khi vào subnet.
Exam reflexPhản xạ khi thi "Third-party firewall / IDS appliances, inline, HA, between VPCs" → GWLB + target group in 2 AZs + GWLB endpoints, TGW with appliance mode. "No appliances to manage" → AWS Network Firewall (it uses GWLB under the hood). "Firewall / IDS appliance bên thứ ba, in-line, HA, giữa các VPC" → GWLB + target group 2 AZ + GWLB endpoint, TGW bật appliance mode. "Không muốn quản lý appliance" → AWS Network Firewall (bên dưới cũng dùng GWLB).

Routing algorithmsRouting algorithm

Round Robin ALB default · CLB TCP · even spreadALB mặc định · CLB TCP · chia đều
Least Outstanding Req ALB option · CLB HTTP · fewest in-flight winsALB tùy chọn · CLB HTTP · ít request in-flight nhất thắng
Weighted Random ALB · enables Automatic Target Weights (anomaly mitigation)ALB · bật được Automatic Target Weights (giảm tải target lỗi)
Flow Hash NLB / GWLB · same flow → same targetNLB / GWLB · cùng flow → cùng target

NLB — zonal DNSNLB — zonal DNS

Prefix the AZ to the DNS name to talk to the NLB node in your AZ — kills inter-AZ data-transfer cost. Prefix AZ vào DNS name để nói với NLB node cùng AZ — triệt tiêu phí inter-AZ.

my-nlb-abcd.elb.us-east-1.amazonaws.com          -> all AZ IPs
us-east-1a.my-nlb-abcd.elb.us-east-1.amazonaws.com -> only 1a IP

Auto Scaling GroupAuto Scaling Group

Pick a scaling policy that matches your signal shape. Update instances via Instance Refresh — never edit in-place. Chọn scaling policy theo hình dáng signal. Update instance qua Instance Refresh — không sửa in-place.

Target tracking "Keep CPU ≈ 40%" · simplest"Giữ CPU ≈ 40%" · đơn giản nhất
Simple / Step CloudWatch alarm → add/remove NCloudWatch alarm → thêm/bớt N
Scheduled Black Friday · 11.11 · known peaksBlack Friday · 11.11 · peak biết trước
Predictive ML forecast · schedule aheadML forecast · lịch trước
Good metricsMetric tốt CPUUtilization · RequestCountPerTarget · Network In/Out · any custom CloudWatch metric. CPUUtilization · RequestCountPerTarget · Network In/Out · custom CloudWatch metric.

Health checks & lifecycle hooksHealth check & lifecycle hook

  • EC2 status · ELB health · Custom (via CLI/SDK set-instance-health). Keep the check fast — no DB query. EC2 status · ELB health · Custom (qua CLI/SDK set-instance-health). Health check phải nhanh — không query DB.
  • Lifecycle hooks — pause before-in-service or before-terminate to do cleanup / log extraction / drain. Lifecycle hook — dừng trước khi vào service hoặc trước terminate để cleanup / lấy log / drain.
  • ASG launches after terminating an unhealthy instance — you can suspend processes for maintenance. ASG launch sau khi terminate instance unhealthy — có thể suspend process khi bảo trì.
  • Deregistration delay (connection draining) — default 300 s; lower it (~120 s) so deploys don't hang on idle connections. Deregistration delay (connection draining) — mặc định 300 s; hạ xuống (~120 s) để deploy không treo vì connection idle.
  • Warm pools — pre-initialized stopped/hibernated instances join the ASG fast on scale-out; no compute billed while stopped (EBS only). Warm pool — instance stopped/hibernated đã init sẵn, vào ASG nhanh khi scale-out; không tính tiền compute lúc stopped (chỉ EBS).
  • Zonal shift (Application Recovery Controller) — one action pulls the ALB/NLB out of an impaired AZ; check remaining-AZ capacity first. Zonal shift (Application Recovery Controller) — một thao tác rút ALB/NLB khỏi AZ lỗi; kiểm tra capacity các AZ còn lại trước.

Update strategiesChiến lược update

Instance Refresh min healthy % + warm-up · in-placemin healthy % + warm-up · in-place
Double + drainNhân đôi + drain 2× fleet · shift traffic · shrinkgấp đôi fleet · chuyển traffic · thu về
New target groupTG mới weighted swap on same ALBswap weighted trên cùng ALB
Blue/green ALBBlue/green ALB two ALBs, flip DNShai ALB, đổi DNS

Target types — the full matrixLoại target — ma trận đầy đủ

Wrong-target-type is one of the cheapest ways an answer gets eliminated. There are only four rows to remember, and two of them are asymmetries. Sai loại target là một trong những cách rẻ nhất để loại một đáp án. Chỉ có bốn dòng cần nhớ, và hai trong số đó là bất đối xứng.

TargetTarget ALB NLB GWLB
instance (EC2 ID)✓✓✓
ip (private IP)✓✓✓
lambda✓ — only ALB✗✗
alb (an ALB as a target)✗✓ — only NLB✗
  • NLB → ALB is legal; ALB → NLB is not. The useful direction combines the NLB's static IPs and PrivateLink with the ALB's L7 routing and WAF.NLB → ALB hợp lệ; ALB → NLB thì không. Chiều hữu ích kết hợp IP tĩnh và PrivateLink của NLB với routing L7 và WAF của ALB.
  • "ECS" and "EKS" are not target types. ECS on EC2 registers as instance or ip; Fargate and awsvpc containers register as ip; Kubernetes pods register as ip."ECS" và "EKS" không phải loại target. ECS trên EC2 đăng ký dạng instance hoặc ip; Fargate và container awsvpc đăng ký dạng ip; pod Kubernetes đăng ký dạng ip.
  • Registering "the cluster name" with a load balancer isn't a thing either — you register tasks, via a target group.Đăng ký "tên cluster" vào load balancer cũng không tồn tại — bạn đăng ký task, qua target group.
  • The ip type also reaches private IPs in a peered VPC or on-premises over VPN/Direct Connect — that's how a load balancer fronts something outside the VPC.Loại ip còn với tới được private IP trong VPC peered hoặc on-premises qua VPN/Direct Connect — đó là cách load balancer đứng trước thứ nằm ngoài VPC.
  • API Gateway has no targets. Its backends are called integrations: Lambda, an AWS service action, a public HTTP endpoint, a private ALB/NLB/Cloud Map through a VPC Link, or a mock.API Gateway không có target. Backend của nó gọi là integration: Lambda, một action của AWS service, một HTTP endpoint public, một ALB/NLB/Cloud Map private qua VPC Link, hoặc mock.

TLS — terminate, re-encrypt, or pass throughTLS — terminate, mã hoá lại, hay pass through

"End-to-end encryption" does not mean "one unbroken TLS session". It means no plaintext hop. Two chained TLS sessions satisfy it; one TLS session and one plaintext hop does not. "End-to-end encryption" không có nghĩa "một phiên TLS liền mạch". Nó nghĩa là không có chặng nào plaintext. Hai phiên TLS nối nhau là đạt; một phiên TLS cộng một chặng plaintext thì không.

Three TLS topologies. First, ALB terminating TLS with an HTTP target group: the client to load balancer leg is encrypted with an ACM certificate, but the load balancer to EC2 leg is plaintext, so this fails an end-to-end encryption requirement. Second, ALB terminating and re-encrypting with an HTTPS target group: two separate TLS sessions, an ACM certificate on the ALB and another certificate installed on each EC2 instance; both legs are encrypted so the requirement is met. Third, NLB with a TCP listener and a TCP target group: the load balancer does not decrypt at all, the client's TLS session terminates on the EC2 instance itself, and only the instance needs a certificate. A note says ALB must always terminate TLS because it needs to read HTTP headers to route, and that port 443 alone does not imply encryption on the back leg. ① ALB terminate, HTTP target group → NOT end-to-end client HTTPS · ACM cert ALB HTTP · plaintext EC2 one plaintext hop → fails the requirement ② ALB terminate + re-encrypt, HTTPS target group → end-to-end ✓ client TLS session 1 · ACM ALB TLS session 2 EC2 + cert two independent sessions; ALB does not validate the target's certificate ③ NLB TCP:443 listener + TCP:443 target group → true passthrough client one unbroken TLS session — NLB just forwards TCP NLB · no cert EC2 + cert only the instance holds a certificate "listen on 443 and forward to 443" says nothing about the back leg: TLS:443 → TCP:443 decrypts and re-sends in the clear

The exam sentence to watch for is a target group whose protocol is unstated. A port number is not a protocol — TLS:443 forwarding to TCP:443 is a decrypt-then-plaintext path.

Câu cần cảnh giác trong đề là một target group không nói rõ protocol. Số port không phải protocol — TLS:443 chuyển tới TCP:443 là đường giải mã rồi gửi trần.

ALB NLB TLS NLB TCP
Decrypts the trafficGiải mã traffic✓ always✓ luôn luôn✓✗
True TLS passthroughTLS passthrough thật✗✗✓
Certificate needed on the LBLB cần certificate✓ ACM✓ ACM/IAM✗
Host/path routing, WAF, OIDC authRoute theo host/path, WAF, OIDC auth✓✗✗
  • ALB can never pass TLS through. It works at L7, so it must decrypt to read the host header, path, cookies and method. If a requirement is "the load balancer must not be able to see the traffic", the answer is an NLB with a TCP listener.ALB không bao giờ pass through TLS được. Nó làm việc ở L7 nên phải giải mã để đọc host header, path, cookie và method. Nếu yêu cầu là "load balancer không được nhìn thấy traffic", đáp án là NLB với TCP listener.
  • ALB's "mTLS passthrough" mode is not TLS passthrough — the ALB still terminates, extracts the client certificate, and forwards its details to the backend as HTTP headers for the app to verify.Chế độ "mTLS passthrough" của ALB không phải TLS passthrough — ALB vẫn terminate, lấy client certificate, rồi chuyển thông tin của nó xuống backend qua HTTP header để app tự kiểm.
  • Certificates are never "installed on" an NLB. A third-party certificate is imported into ACM or IAM, then associated with the TLS listener.Certificate không bao giờ được "cài lên" NLB. Certificate bên thứ ba phải import vào ACM hoặc IAM, rồi associate với TLS listener.
  • A plain ACM public certificate cannot be exported onto EC2 (the exportable option is opt-in at request time, and older certificates can't do it at all) — which is why classic exam answers pair "ACM cert on the ALB" with "third-party cert on the instances". On EC2, ACME/Let's Encrypt is the practical alternative.Certificate public ACM thường không export ra EC2 được (tuỳ chọn exportable phải bật lúc yêu cầu certificate, và certificate cũ thì không làm được) — đó là lý do đáp án kinh điển ghép "ACM cert trên ALB" với "cert bên thứ ba trên instance". Trên EC2, ACME/Let's Encrypt là lựa chọn thực tế.
  • The ALB does not validate the target's certificate on the back leg, so a self-signed certificate on EC2 still satisfies "encrypted in transit".ALB không kiểm tra certificate của target ở chặng sau, nên certificate self-signed trên EC2 vẫn thoả "mã hoá khi truyền".

Static IPs — one Elastic IP per AZIP tĩnh — mỗi AZ một Elastic IP

When a partner's firewall needs a fixed address, an internet-facing NLB with one Elastic IP per subnet/AZ is the whole answer. Route 53 still points the name at the NLB with an A (Alias) record; the partner allow-lists the EIPs. Khi firewall của đối tác cần một địa chỉ cố định, NLB internet-facing với mỗi subnet/AZ một Elastic IP là toàn bộ đáp án. Route 53 vẫn trỏ tên miền vào NLB bằng record A (Alias); đối tác allow-list các EIP.

my.service.com          →  A (Alias)  →  NLB
                                          ├── AZ-a  →  EIP 203.0.113.10  ┐  đối tác allow-list
                                          └── AZ-b  →  EIP 203.0.113.11  ┘  CẢ HAI
targets: EC2 in private subnets, private IPs only
client connects to  my.service.com:9000   (DNS carries no port — the client must know it)
  • Give the partner every EIP, one per AZ. Allow-listing only one means losing the service when that AZ has a problem.Đưa đối tác tất cả EIP, mỗi AZ một cái. Chỉ allow-list một cái nghĩa là mất dịch vụ khi AZ đó có sự cố.
  • The EIP goes on the NLB, not on the instances. Targets stay in private subnets with private IPs only.EIP gắn vào NLB, không gắn vào instance. Target vẫn ở private subnet và chỉ có private IP.
  • Without an allow-list requirement you don't need EIPs at all — an internet-facing NLB gets AWS-assigned public addresses and the DNS name is enough.Không có yêu cầu allow-list thì chẳng cần EIP — NLB internet-facing được AWS cấp địa chỉ public và dùng DNS name là đủ.
  • Pointing DNS straight at the instances' EIPs bypasses the load balancer and loses health checking. And an NS record designates name servers — it never maps a name to an IP; that's an A record.Trỏ DNS thẳng vào EIP của instance là bỏ qua load balancer và mất health check. Còn record NS dùng để chỉ định name server — nó không bao giờ ánh xạ tên sang IP; đó là việc của record A.
  • Need static IPs across several Regions instead? That's Global Accelerator.Cần IP tĩnh trải trên nhiều Region? Đó là Global Accelerator.