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 →
- 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 - Fix the health check path and port, and the SG rule from the ALB SG
- To debug a live instance, suspend
ReplaceUnhealthyfor 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.