The signature#
On the EC2 launch type, a deployment stalls and the service events say:
service (service-name) was unable to place a task because no container instance met all of its requirements. The closest matching container-instance container-instance-id encountered error "AGENT".
The ECS container agent on that instance is disconnected. Only instances with a connected agent can accept task placement requests, so ECS skips the instance even when it has free CPU and memory. The cause can also appear without this exact text. AWS lists a disconnected agent as a common cause of the SERVICE_TASK_PLACEMENT_FAILURE service action event, beside a lack of CPU or memory. A task already assigned to an instance can also stay PENDING, the state in which ECS waits on the container agent, and the instance's pendingTasksCount counts it. Service event messages · ContainerInstance agentConnected · Service action events · Task lifecycle
A brief disconnect is normal. AWS says the agent disconnects and reconnects several times per hour as part of normal operation, so a single connection change in EventBridge is not a fault. A disconnect that lasts through repeated placement attempts is. Container instance state change events
Read every instance's agent state#
Use a read-only profile and replace the uppercase placeholders. List the instances, then describe them with their health included.
aws ecs list-container-instances \
--profile PROFILE --region REGION --cluster CLUSTER \
--query 'containerInstanceArns' --output json --no-cli-pager
aws ecs describe-container-instances \
--profile PROFILE --region REGION --cluster CLUSTER \
--container-instances CONTAINER_INSTANCE_ARN_1 CONTAINER_INSTANCE_ARN_2 \
--include CONTAINER_INSTANCE_HEALTH \
--query 'containerInstances[].{ec2:ec2InstanceId,status:status,reason:statusReason,agent:agentConnected,version:versionInfo.agentVersion,update:agentUpdateStatus,running:runningTasksCount,pending:pendingTasksCount,health:healthStatus.overallStatus,checks:healthStatus.details[].{type:type,status:status,since:lastStatusChange}}' \
--output json --no-cli-pager
The fields answer different questions:
agentConnectedis false for an instance whose agent may be unhealthy or stopped.statusis the registration state. OnlyACTIVEaccepts tasks;DRAININGtakes no new tasks by design, andREGISTRATION_FAILEDcomes with astatusReason.versionInfo.agentVersionandagentUpdateStatusshow the agent release and whether its last updateFAILED.healthStatus, returned only withCONTAINER_INSTANCE_HEALTH, reports checks run by agent 1.57.0 or later. Its overall status isOK,IMPAIRED,INSUFFICIENT_DATAorINITIALIZING, and the check types includeCONTAINER_RUNTIMEandAGENT_CONNECTIVITY.
ContainerInstance fields · Container instance health · describe-container-instances
Match the disconnected instances' EC2 IDs with the EC2 or Auto Scaling view. A terminated instance whose agent was disconnected is not deregistered automatically, so it can stay in the list as a container instance that never reconnects. Deregistering container instances
What the pattern means#
| Pattern | Likely cause | Next check |
|---|---|---|
One instance agent false, others true | That host's agent stopped or is unhealthy, or the host itself is impaired | The agent log on that host; CONTAINER_RUNTIME health |
| Every instance false at about the same time | A shared dependency: the network path to ECS, DNS for VPC endpoints, or the instance role | Route tables, endpoint security groups and the role, around the time it started |
agent false; the EC2 instance no longer exists | A stale registration | Deregister the record; it does not hold tasks |
agent true; status DRAINING or REGISTRATION_FAILED | Not an agent problem | Who drained the instance, or the statusReason |
agent true; update FAILED or an old version | The agent runs but lacks a feature the task needs | Placement fails on a missing attribute instead; update the agent or replace the instance |
The agent needs a container instance IAM role so ECS knows the agent belongs to your account. Without an internet path, it reaches ECS through the ecs-agent, ecs-telemetry and ecs interface endpoints, which must be in the same Region and whose security group must allow inbound TCP 443 from the instances' subnets. Using these endpoints with EC2 tasks requires agent 1.25.1 or later, and instances running before the endpoints were created must reboot or restart the agent to use them. Container instance role · ECS interface endpoints
Look at the host#
For a single disconnected instance, connect to it with your usual access method and read the agent log. For agent 1.36.0 and later on Linux, the log is at /var/log/ecs/ecs-agent.log, rotated hourly and kept for 24 hours by default. Read the entries around the time the instance stopped accepting tasks for authentication, connection or Docker errors. Agent logs
These commands change the host. On the Amazon ECS-optimized Amazon Linux 2 AMI, AWS suggests restarting the agent with sudo systemctl restart ecs. Restarting does not fix a cause outside the host, and for an instance in an Auto Scaling group, replacing it with a fresh launch is often quicker than repairing it. Service event messages
An illustrative fixture#
This fixture is fictional. The cluster checkout has three container instances. A deployment of checkout:42 starts at 14:00 and its tasks do not place.
In the first case i-0a1 reads agent false, version 1.82.0, health IMPAIRED with the CONTAINER_RUNTIME check failing since 13:41. The other two read agent true and have no room left for the new tasks. ECS would have used i-0a1, which holds no tasks, but cannot. The agent log on i-0a1 shows the agent losing its connection to Docker. Replace i-0a1, and the deployment places on the new instance.
In the second case all three read agent false from 13:52, the same minute a network change removed the private subnet's route to a NAT gateway. The cluster has no ECS interface endpoints, so the agents have no path to ECS. Restarting agents changes nothing. Restore the route or create the three endpoints, then confirm that agent returns to true on each instance.
Confirm on the replacement#
After the change, every ACTIVE instance should read agent true and an OK overall health, and the service events should stop naming error AGENT. Check that new tasks reach RUNNING with a containerInstanceArn on the repaired or replaced instances, and that the service reports a steady state. Service event messages
Where the reading misleads#
agentConnected is a current value. An agent that reconnected after you noticed the failure reads true, so keep the ECS Container Instance State Change events or the service events from the incident window as the record. An IMPAIRED health status is ECS's view from the agent's checks; it names the failing check type, not the root cause on the host.
A disconnected agent and a full cluster can both end in a placement failure. When the event names insufficient CPU or memory but the numbers show free resources on some instance, check that instance's agentConnected before adding capacity, because a disconnected instance takes no tasks whatever it has free. See the CPU and memory guide, tasks stuck in PROVISIONING for instances that never registered, and the signature table for other layers.
Questions#
What does error AGENT mean in an ECS placement event?
The ECS container agent on the closest matching container instance is disconnected, so ECS cannot place tasks there. Read that instance's agentConnected, status and agent log.
Is it normal for the ECS agent to disconnect?
Yes, briefly. AWS says the agent disconnects and reconnects several times per hour as part of normal operation. A disconnect that keeps an instance unavailable through repeated placement attempts is a fault.
Why are all my ECS container instances disconnected at once?
When every agent drops together, look for what they share: a route or NAT change, missing or misconfigured ECS interface endpoints, DNS for those endpoints, or the container instance role. Restarting each agent does not fix a shared cause.