ECS cluster has no ecs instances but two ecs instances are visible in EC2

Solution 1:

You indicated in your comment that the instances have no public IP addresses. I'm extrapolating from that comment that your instances likely have no route to the Internet as well.

In order to use ECS, your instances need to have a route to reach (at a minimum) the ECS service endpoints. A route to the Internet can be through an Internet Gateway (IGW), Network Address Translation (NAT), or through an HTTP Proxy. Without a route to reach the ECS service endpoints, the ECS agent will be unable to register itself into your cluster and you will be unable to use those instances with ECS.

Solution 2:

Fixed the issue by following the following two steps:

1) Make sure 'auto-assign public IPv4 address' is enabled

enter image description here

2) Create and attached a gateway to the VPC. Then add a route to the gateway.

enter image description here