Health checks, draining and instance refresh
Running is not the same as ready
An EC2 instance can be running while its application returns errors. A load balancer checks targets using a configured protocol, port, path where applicable, timeout and success/failure thresholds. For the bookstore use an HTTP readiness endpoint /ready that returns 200 only when the instance can serve the intended work. A health check is a sampled signal, not proof every request succeeds. Inspect logs and target health reasons when a check fails.
/ready -> 200 when ready/ready -> 503 while initializingSeparate routing health from replacement
EC2 Auto Scaling uses EC2 health checks by default; enable ELB health checks for the group when you want load balancer health to participate in replacement decisions. A health-check grace period gives a new instance time to initialize before optional health failures cause replacement; it does not stop ELB probing. A misconfigured health path can make healthy apps appear unhealthy and cause repeated replacements if ELB checks are enabled. Verify the app port, path, success codes and permitted health traffic. When all targets are unhealthy, ALB can fail open and route to unhealthy targets, so health checks are not access control.
Drain before removing capacity
Deregistering a target normally stops sending it new work while existing requests or connections have time to finish. This is connection draining, controlled by deregistration delay and type-specific settings. It cannot guarantee that long-lived requests finish; NLB connection termination behavior is configurable in applicable cases. Design bounded request durations and graceful application shutdown. A termination lifecycle hook can pause termination for approved cleanup, with a timeout and failure policy; do not rely on it as the sole copy of durable data.
target A: draining, active requests=2target B: healthy, accepts new requestsInstance refresh is a deployment operation
Instance refresh replaces instances in a group with a desired configuration, for example a reviewed new launch template version. Choose minimum and maximum healthy percentages, warmup and health settings appropriate to the workload. Checkpoints, alarms and rollback options can help with controlled rollout; verify their prerequisites. In a toy group with four desired instances, a requirement of at least three ready instances leaves room for one unavailable instance at a time. This arithmetic is not the actual instance refresh scheduling algorithm. If a replacement fails readiness, stop promotion, investigate and use the approved rollback plan.
desired=4; minimum ready=3ready=3 -> meets worksheet floorready=2 -> violates worksheet floorPractice: separate three decisions
A surge in demand calls for a scaling decision; a failed health check calls for diagnosis and potentially replacement; a new release calls for a deployment decision. These can overlap but should not be confused. In the offline lab calculate the spare capacity after one zone fails, identify a draining target and decide whether a rollout may proceed. Before any separately authorized live lab, estimate costs, check region and account, cap ordinary capacity, bound test traffic and verify cleanup of ASG, load balancer, target groups and related billable resources. Never terminate unrelated instances.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Health checks, draining and instance refresh — knowledge check
Apply the fictional bookstore scaling and delivery design.
An EC2 instance runs but /ready returns 503. What does this show?
Which action makes ELB health failures participate in ASG replacement decisions?
What is the purpose of connection draining during deregistration?
A rollout worksheet requires 3 ready instances out of 4. Only 2 are ready. What should the operator do?
Which operation is intended to replace instances with a new launch template configuration?