Interview Prep/AWS/EC2, Auto Scaling and Load Balancing

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 →

  1. Look at the activity history: aws autoscaling describe-scaling-activities --auto-scaling-group-name web
  2. Check cause text such as "Terminating EC2 instance: health check type ELB"
  3. Increase HealthCheckGracePeriod beyond boot plus app start time
  4. Read /var/log/cloud-init-output.log via a suspended instance
  5. Use aws autoscaling suspend-processes --scaling-processes ReplaceUnhealthy to 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.

aws All AWS questions Roadmap: AWS core services

More on EC2, Auto Scaling and Load Balancing