AWS ECS – Auto Scaling Group Instances Not Registering to ECS Cluster

amazon-ecsamazon-web-services

I have created an ECS cluster linked to an Autoscaling group with an Application load balancer attached. The Autoscaling deploys the instances, the AMI is correctly choosen (ECS optimized).

for whatever reason the ecs instances are being deployed by the Auto Scaling service but are not registering with the ECS Cluster.

Does anybody have an idea, what could cause the error of not having the instances on my cluster?

Best Answer

Your EC2 instances just don't have enough permissions to register with ECS cluster:

Important

If you do not launch your container instance with the proper IAM permissions, your Amazon ECS agent cannot connect to your cluster.

Check IAM role that you've assigned to your EC2 instances. It should include appropriate permissions, for example:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "ecs:DeregisterContainerInstance",
        "ecs:RegisterContainerInstance",
        "ecr:GetAuthorizationToken"
      ],
      "Resource": "*"
    }
  ]
}

Or you can use AWS-managed policy named AmazonEC2ContainerServiceforEC2Role and assigned it to your EC2 role.

More information is avalable at https://docs.aws.amazon.com/AmazonECS/latest/developerguide/instance_IAM_role.html.