Skip to content

The ECS service is not receiving the health status information from the load balancer consistently. It sometimes works, it sometimes doesn't. Why?

0

We are experiencing cases where the EC2 load balancers detect an unhealthy host condition on an ECS service.

However, ECS is not logging or responding to these conditions so makes no effort to replace the faulty ECS service.

The issue is intermittent - the ECS service does sometimes log and react to health issues with the same service. However, it appears to do this intemittently, it sometimes works and sometimes fails.

The issue is not that the ECS task is failing - the issue is the fact that ECS is sometimes failing to detect the presence of a failure condition with the task and so does automatically restore the service - a key feature of ECS that we are paying premium for.

asked a year ago232 views

1 Answer
0

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:

  1. 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.

  2. 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 loadBalancers configuration block
  • The healthCheckGracePeriodSeconds parameter 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:

answered a year ago

AWS
SUPPORT ENGINEER

reviewed 5 months ago

AWS
SUPPORT ENGINEER

revised 5 months 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.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.