Search code examples
amazon-web-servicesamazon-ec2amazon-ecs

Why doesn't my EC2 instance register with the ECS cluster


I am creating an AWS ECS cluster (Networking + Linux).

I follow all the steps, set up the subnets and use the existing VPC and the EC2 instance is created.

However, when I go into my cluster > ECS Instances I don't see any EC2 instances there. It doesn't seem to register there.

My EC2 instance has a public IP so that should not be an issue. What could be the problem?


Solution

  • You haven't specified in the question, but normally you also should modify your UserData so that it registers with the non-default cluster:

    #!/bin/bash
    echo ECS_CLUSTER=<your-cluster-name> >> /etc/ecs/ecs.config
    

    Also Amazon ECS-optimized AMI should be used which has pre-installed ECS Agent.

    Edit: Also need to make sure that instances have access to the ECS Service, for example by having public IP and internet access. Without that, ECS Agent won't be able to communicate with the ECS Service.

    UserData in console can be specified in the following configuration:

    enter image description here

    You can also use Launch Templates or Launch Configurations to specify the UserData reduce the amount of work needed when launching new instances.