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 | ✅ | ❌ |
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.
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.
Routing algorithmsRouting algorithm
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.
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/SDKset-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
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 → ALBis legal;ALB → NLBis not. The useful direction combines the NLB's static IPs and PrivateLink with the ALB's L7 routing and WAF.NLB → ALBhợp lệ;ALB → NLBthì 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
instanceorip; Fargate andawsvpccontainers register asip; Kubernetes pods register asip."ECS" và "EKS" không phải loại target. ECS trên EC2 đăng ký dạnginstancehoặcip; Fargate và containerawsvpcđăng ký dạngip; pod Kubernetes đăng ký dạngip. - 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
iptype 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ạiipcò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.
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
NSrecord designates name servers — it never maps a name to an IP; that's anArecord.Trỏ DNS thẳng vào EIP của instance là bỏ qua load balancer và mất health check. Còn recordNSdùng để chỉ định name server — nó không bao giờ ánh xạ tên sang IP; đó là việc của recordA. - 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.