โšก Onwuachi Control Plane

ASG Self-Healing Patterns and Instance Refresh

Overview

ASG self-healing is not a single feature โ€” it is the composition of ELB health checks, ASG health check type, lifecycle hooks, and Instance Refresh working together. This article covers the full loop, how each piece contributes, and what breaks when one piece is misconfigured.

Why It Matters

EC2 health checks only detect VM failure. An application can crash while the instance stays running and passes EC2 checks โ€” traffic keeps routing to a broken instance. ELB health checks close this gap. Instance Refresh closes the drift gap โ€” ensuring the fleet always runs the current Launch Template version. Together they form a self-healing system that requires no human intervention for both failure recovery and fleet updates.

Where It Fits

DOP-C02 Domain 3 โ€” Resilient Cloud Solutions

Application failure detected by ALB | v Target Group marks instance unhealthy | v ASG (health-check-type: ELB) terminates instance | v Lifecycle hook: Pending:Wait (bootstrap runs) | v CONTINUE โ†’ InService โ†’ ALB registers target | v Traffic restored โ€” no human intervention


The Big Picture

Two failure modes, two recovery paths:

VM failure: EC2 check fails โ†’ ASG detects Current < Desired โ†’ replacement launches

App failure (VM healthy): ELB check fails โ†’ Target Group unhealthy โ†’ ASG terminates โ†’ replacement launches (only works when health-check-type = ELB)

Fleet drift (old AMI): Instance Refresh โ†’ rolling replacement โ†’ MinHealthyPercentage maintained


Core Concepts

Health check type โ€” the critical setting:

Health check grace period โ€” how long ASG waits after launch before starting ELB checks. Must be longer than your bootstrap time or healthy instances get terminated mid-startup.

Instance Refresh โ€” rolls the entire fleet to a new Launch Template version:

Orphaned ELB health check โ€” if health-check-type is ELB but no live Target Group/ALB is attached, all ASG activity stalls. Instances can never pass health checks, Instance Refresh hangs at 0%. Always audit after tearing down an ALB.


Real-World Example

Live lab in devopslab-vpc, ASG dop-lab-asg:

Instance Refresh โ€” first attempt (failed):

Instance Refresh โ€” second attempt (successful):

Audit commands when ASG behavior is unexpected:

# Check health check type and attached target groups
aws autoscaling describe-auto-scaling-groups \
  --auto-scaling-group-name <asg-name> \
  --query "AutoScalingGroups[0].{HealthCheckType:HealthCheckType,HealthCheckGracePeriod:HealthCheckGracePeriod,TargetGroupARNs:TargetGroupARNs}" \
  --output json

# Check lifecycle hooks
aws autoscaling describe-lifecycle-hooks \
  --auto-scaling-group-name <asg-name> \
  --output table

# Check active refreshes
aws autoscaling describe-instance-refreshes \
  --auto-scaling-group-name <asg-name> \
  --output table

Engineering Analogy

Instance Refresh maps directly to your Packer + platform-foundation deploy workflow โ€” you bake a new AMI, update the Launch Template, and need all running instances replaced with the new version. Without Instance Refresh you’d manually terminate instances and watch ASG replace them one by one. Instance Refresh automates that rolling replacement with a guaranteed minimum healthy percentage โ€” equivalent to a zero-downtime deploy in your CI/CD pipeline.


Best Practices


Common Mistakes


Pro Tip

When Instance Refresh stalls at 0% / InProgress, the first thing to check is not the refresh itself โ€” it’s the ASG config. Orphaned ELB health checks and attached lifecycle hooks are the two most common blockers. Run the audit commands above before touching the refresh.


Key Takeaways


Related Articles


References

System Context

โ† Back to Kb