Search code examples
amazon-web-servicesamazon-ec2aws-cliamazon-ecs

AWS ECS CLI Doesn't Attach EC2 Instance To Cluster


I have some docker containers, and I'm trying to launch them on AWS ECS using the ECS CLI.

These are my commands:

ecs-cli configure --cluster abc --default-launch-type FARGATE --config-name abc-conf --region eu-west-1

ecs-cli configure profile --access-key xxx --secret-key xxx --profile-name abc-profile

ecs-cli up --security-group sg-094607105993d0351 --vpc vpc-0479323e6e7107b74 --subnets subnet-009eb5c6e08b7dbf0,subnet-0e1c2846b268b170a --keypair abc-key --capability-iam --size 1 --instance-type t2.small --cluster-config abc-conf --ecs-profile abc-profile --region eu-west-1 --force

ecs-cli compose up --create-log-groups --cluster-config abc-conf --ecs-profile abc-profile --create-log-groups

However I get

ERRO[0001] Error running tasks                           error="InvalidParameterException:     No Container Instances were found in your cluster." task definition=0xc00031e6a0
FATA[0001] InvalidParameterException: No Container Instances were found in your cluster. 

The reason for this is that the ecs-cli up command is bringing up an EC2, but it is not bringing it inside the cluster, so the cluster has no instances.

Now this works if I don't specify my own vpc and subnets, however I have to do that as there is no other way to specify a bunch of ports to open on the cluster (there is an option that only allows you to specify one port).

So why is ecs-cli not bringing my instance inside my cluster?


Solution

  • Finally found the answer. You have to add an internet gateway to your VPC; then in the subnet that you are trying to launch your cluster, you have to add a route table entry pointing 0.0.0.0/0 to the internet gateway. It will then instantly attach the ec2 to your cluster.