- Newest
- Most votes
- Most comments
The load balancer detected an unhealthy target, but ECS did not replace the task for 2.5 days. This points to how ECS is configured to evaluate task health rather than a connectivity or timing issue.
ECS has two task health evaluation modes:
-
Container-level (default): ECS only checks if the container process is running. If the process is alive, the task is considered healthy regardless of what the load balancer reports.
-
ELB-integrated: ECS uses the load balancer's target health status to determine whether to replace a task. If the target is marked unhealthy by the ALB/NLB, ECS stops and replaces it.
ECS will only use load balancer health for task replacement if ALL of the following are true:
- The service was created with a
loadBalancersconfiguration block - The
healthCheckGracePeriodSecondsparameter is set on the service - The task is registered as a target in the target group
If healthCheckGracePeriodSeconds is not set (or is 0), ECS may not properly integrate the ELB health status into its task lifecycle decisions.
The intermittent behaviour you describe (sometimes ECS reacts, sometimes it does not) is likely because:
- When the container process crashes entirely, ECS detects this through task state (STOPPED) and replaces it. This works regardless of ELB configuration.
- When the application becomes unhealthy but the process keeps running (e.g., returns 503s, stops responding on the health check path), only the ELB detects this. If ECS is not configured to use ELB health, it will not replace the task.
To verify, run:
aws ecs describe-services \
--services your-service-name \
--cluster your-cluster-name \
--query 'services[0].{healthCheckGracePeriod:healthCheckGracePeriodSeconds,loadBalancers:loadBalancers,desiredCount:desiredCount}'
If healthCheckGracePeriodSeconds is null or missing, set it to a value appropriate for your application startup time (e.g., 60 to 120 seconds). This enables ECS to use the load balancer health status for task replacement decisions.
aws ecs update-service \
--service your-service-name \
--cluster your-cluster-name \
--health-check-grace-period-seconds 120
After this change, ECS will replace tasks that the load balancer marks as unhealthy once the grace period has elapsed.
References:
- ECS service load balancing: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/service-load-balancing.html
- Health check grace period: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/service-health-checks.html
answered a year ago
Relevant content
asked 4 years ago

None of these conditions apply. The EC2 monitor detected an healthy host on November 7 at 22:00. ECS did not long single thing in relatied to this host until we manually initiated recovery actions at 12:00 on November 10 (all times UTC+11:00).
In other words, ECS apparently did not receive any notifications the the target group monitoring during the 2.5 days where the EC2 detected condition was present.