Instances in an ASG keep getting terminated and replaced in a loop. What is going on?
IntermediateScenarioEC2, Auto Scaling and Load Balancing
Answer
Situation read → Health checks are failing before the app is ready, or user data is crashing.
What I'd do →
- Look at the activity history:
aws autoscaling describe-scaling-activities --auto-scaling-group-name web - Check cause text such as "Terminating EC2 instance: health check type ELB"
- Increase
HealthCheckGracePeriodbeyond boot plus app start time - Read
/var/log/cloud-init-output.logvia a suspended instance - Use
aws autoscaling suspend-processes --scaling-processes ReplaceUnhealthyto debug
Why → ELB health checks start immediately after grace period; a slow boot keeps tripping them.
Interview tip → Suspending ReplaceUnhealthy is the debug trick that proves you have done this.