How to Add EC2 Instance to ECS Cluster Using AWS Node SDK

I am trying to programmatically create an ECS cluster with an EC2 instance in it. As I understand it, I must first create an ECS cluster than an EC2 instance and then register the instance using this method:

http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/ECS.html#registerContainerInstance-property

How am I supposed to do this? What arguments are required? How to get instanceIdentityDocument and instanceIdentityDocumentSignature?

thank

+3


source to share


1 answer


I would use custom EC2 instance data to launch the instance directly to the ECS cluster. This is the user data you want to use:

#!/bin/bash
echo ECS_CLUSTER=your_cluster_name >> /etc/ecs/ecs.config

      



See the AWS docs for details . You can also use this custom data in the auto scale launch configuration.

Also, it might be worth looking at the languages ​​in which the provisioning infrastructure is done, such as Terraform (also for AWS) or CloudFormation (specifically for AWS).

+3


source







All Articles