Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to register EC2 Instance to ECS cluster?

I have started 2 ECS optimized instances on EC2, but how can I register them as ECS container instances ?

Can not figure out a way of doing that.

like image 787
Hello lad Avatar asked Apr 06 '16 21:04

Hello lad


2 Answers

When you start an ECS optimized image, it starts the ECS agent on the instance by default. The ecs agent registers the instance with the default ecs cluster.

For your instance to be available on the cluster, you will have to create the default cluster.

if you have a custom ecs cluster, you can set the cluster name using the userdata section.

The ecs agent expects the cluster name inside the ecs.config file available at /etc/ecs/ecs.config.

You can set it up at instance boot up using userdata script

#!/bin/bash echo ECS_CLUSTER={cluster_name} >> /etc/ecs/ecs.config 

Please refer to the following ecs documentation for more information http://docs.aws.amazon.com/AmazonECS/latest/developerguide/launch_container_instance.html

like image 65
Shibashis Avatar answered Sep 19 '22 22:09

Shibashis


When you create an EC2 instance, you must specified the IAM role linked to your ECS container (if using SDK/..., you must specified the "Instance Profile ARN" of this role in the parameters), if you use the interactive ECS cluster creation at your first ECS use on the aws website, you should already have an ecsInstanceRole link to the default cluster.

Then, after being launched, your EC2 instance will be automatically register as ECS container in this cluster.

like image 24
DarkCenobyte Avatar answered Sep 17 '22 22:09

DarkCenobyte