ECS cannot run a task because the cluster has no container instances
No Container Instances were found in your clusterShort answer
For the EC2 launch type, a task needs a registered container instance. None are registered when the instance joined the default cluster instead of yours, lacks the ECS instance IAM role, cannot reach the ECS endpoint, or its agent is not running. List the cluster's instances first, then read the agent log.
Fix it fast
1Find out which cause you have
Ask ECS how many container instances the cluster really has. An empty list confirms the instances never registered.
aws ecs list-container-instances --cluster my-cluster aws ecs list-container-instances --cluster default2Match what you see, then jump to its fix
- 1
my-cluster lists nothing, but the default cluster lists the instance.The instance joined the default cluster, not yoursFix - 2
The instance has no IAM instance profile attached.The instance has no ECS instance IAM roleFix - 3
The instance is in a private subnet with no public IP, NAT gateway or interface VPC endpoint.The instance cannot reach the ECS service endpointFix - 4
The instance shows in the cluster but RunTask returns an AGENT failure.The agent is not running or is disconnectedFix
- 1
What does the error look like?
No Container Instances were found in your clusterTaskFailedToStart: EMPTY CAPACITY PROVIDER
Cause 1 of 4
The instance joined the default cluster, not yours
1Check
By default a container instance launches into the cluster named default. It joins another one only when ECS_CLUSTER is set in /etc/ecs/ecs.config.
sudo cat /etc/ecs/ecs.config2Fix
Set the cluster name in the agent config and restart the agent. For a new instance put the same line in the launch user data.
echo ECS_CLUSTER=my-cluster | sudo tee -a /etc/ecs/ecs.config
sudo systemctl restart ecs3Verify
List the instances of your cluster again.
aws ecs list-container-instances --cluster my-clusterConfirmed by docs.aws.amazon.com
Cause 2 of 4
The instance has no ECS instance IAM role
1Check
ECS says the role lets the service know the agent belongs to you; without the proper IAM permissions the agent cannot connect to your cluster. The role is usually named ecsInstanceRole.
aws ec2 describe-instances --instance-ids i-0123456789abcdef0 \
--query "Reservations[].Instances[].IamInstanceProfile.Arn"2Fix
Create ecsInstanceRole with the AmazonEC2ContainerServiceforEC2Role managed policy, attach it to the instance as its instance profile, and restart the agent.
aws iam attach-role-policy \
--role-name ecsInstanceRole \
--policy-arn arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceforEC2Role3Verify
Restart the agent and list the cluster's instances.
sudo systemctl restart ecs
aws ecs list-container-instances --cluster my-clusterConfirmed by docs.aws.amazon.com
Cause 3 of 4
The instance cannot reach the ECS service endpoint
1Check
Container instances must reach the Amazon ECS endpoint, through an interface VPC endpoint, a public IP, or NAT.
sudo tail -n 40 /var/log/ecs/ecs-init.log2Fix
Give the subnet a NAT gateway or an ECS interface VPC endpoint, or turn on Auto-assign Public IP for the instance in a public subnet.
# check the route table of the instance's subnet
aws ec2 describe-route-tables --filters Name=association.subnet-id,Values=subnet-0123456789abcdef03Verify
Restart the agent and check the instance registers.
sudo systemctl restart ecs
aws ecs list-container-instances --cluster my-clusterConfirmed by docs.aws.amazon.com
Cause 4 of 4
The agent is not running or is disconnected
1Check
ECS keeps agent logs in /var/log/ecs on the instance. A disconnected agent makes ECS reject task placement.
sudo systemctl status ecs
sudo cat /var/log/ecs/ecs-init.log2Fix
Restart the ECS agent, then read the log again if it does not come back.
sudo systemctl restart ecs3Verify
The instance appears in the cluster list.
aws ecs list-container-instances --cluster my-cluster --status ACTIVEConfirmed by docs.aws.amazon.com
How do I stop it coming back?
- Put ECS_CLUSTER and the instance profile in the launch template, not in a one-time manual edit.
- Keep ecsInstanceRole attached with the managed policy for every container instance.
- Plan the subnet's route to ECS (NAT or endpoint) before launching private instances.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- Dispatch ProA real-time logistics platform: Flutter apps, Spring Boot services and a Kafka event pipeline on AWS.
- RaheebA consumer app shipped to both stores from one Flutter codebase on a .NET and Azure back end.
- Loade DriverThe driver side of a delivery platform: live jobs, routing and earnings, past 5K Google Play downloads.
Related fixes
Servers
Status code 460 on an AWS Application Load Balancer
elb_status_code 460 in ALB access logs
A 460 is generated by the load balancer, not by your app.
3 causes, each with a fixServers
Application Load Balancer returns 504 for requests to EC2 instances
HTTPCode_ELB_504_Count
A 504 from an Application Load Balancer means it could not get an answer from a target in time.
4 causes, each with a fixServers
Apache has a certificate, but https:// does not open
No line with :443 in the output of ss -ltnp
HTTPS needs four things at once: mod_ssl loaded, Apache listening on 443, a virtual host on 443 with SSLEngine on, and a firewall that lets 443 in.
4 causes, each with a fixServers
aws emr --steps fails: Error parsing parameter, Expected '=', received 'EOF'
Error parsing parameter '--steps': Expected: '=', received: 'EOF' for input:
The AWS CLI tried to read your option as shorthand key=value pairs and ran out of text where it expected an equals sign.
3 causes, each with a fixServers
AWS CLI says you must specify a region
You must specify a region. You can also configure your region by running "aws configure".
The AWS CLI sends every request to one region and has none to use.
4 causes, each with a fixServers
docker login to Amazon ECR fails with: Cannot perform an interactive login from a non TTY device
Cannot perform an interactive login from a non TTY device
Docker asked for a password because none reached it, and a pipe or script has no keyboard to answer.
3 causes, each with a fix