Using AWS SDK for Node.js, how to wait for EC2 instance being added to ECS cluster?
<p>I recently start using AWS, and read its docs.</p>

<p>For my needs, I must deploy EC2 instances from my node.js code, wait they are added to my ECS cluster (via using the right Arn Instance Profile), then start a task on the last EC2 instance started.</p>

<p>But, actually, I didn't find a way to define a task at the EC2 start, because I must override the docker command with a variable from my nodejs and do some other task. So, I must wait the EC2 being added to the ECS cluster before try to startTask() with my params and the Arn from the Container Instance Id (but I can't get it from a listContainerInstances() until).</p>

<p>Is there a way to achieve this easily?
(Actually I try to loop with a setTimeout until the listContainerInstances() return something new, but I don't think it's a good practice at all and my code look a little bit ugly).</p>