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

An ASG keeps launching and terminating instances in a loop; activity history says `an instance was taken out of service in response to an ELB system health check failure`.

IntermediateTroubleshootingEC2, Auto Scaling and Load Balancing
Answer

Likely causes → The ASG uses ELB health checks, but the health check grace period is shorter than the app's boot time. It can also be a wrong health check path, or a target SG that does not allow traffic from the ALB.

Diagnose →

aws autoscaling describe-scaling-activities --auto-scaling-group-name web-asg --max-items 10
aws autoscaling describe-auto-scaling-groups --auto-scaling-group-names web-asg \
  --query 'AutoScalingGroups[].[HealthCheckType,HealthCheckGracePeriod]'
aws elbv2 describe-target-health --target-group-arn <tg-arn>

Fix →

  1. Raise the grace period above the real boot time: aws autoscaling update-auto-scaling-group --auto-scaling-group-name web-asg --health-check-grace-period 300
  2. Fix the health check path and port, and the SG rule from the ALB SG
  3. To debug a live instance, suspend ReplaceUnhealthy for a while: aws autoscaling suspend-processes --auto-scaling-group-name web-asg --scaling-processes ReplaceUnhealthy

Prevent → Use a cheap /healthz endpoint, plus a lifecycle hook or warm pool for slow boots.

aws All AWS questions Roadmap: AWS core services

More on EC2, Auto Scaling and Load Balancing