cari
cari

Reputation: 2302

How can I connect my autoscaling group to my ecs cluster?

In all tutorials for ECS you need to create a cluster and after that an autoscaling group, that will spawn instances. Somehow in all these tutorials the instances magically show up in the cluster, but noone gives a hint what's connecting the autoscaling group and the cluster.

my autoscaling group spawns instances as expected, but they just dont show up on my ecs cluster, who holds my docker definitions.

Where is the connection I'm missing?

Upvotes: 45

Views: 16090

Answers (4)

Sarang
Sarang

Reputation: 2733

This question is old but the answer is not complete. There are 2 parts to getting your own auto-scaling group to show up in your cluster (as of Jan 2022).

  1. You need to ensure your cluster name is set for ECS_CLUSTER variable in /etc/ecs/ecs.config as mentioned in this answer: https://stackoverflow.com/a/35324937/583875

  2. You need to create a new capacity provider for the cluster and attach this auto scaling group. To do this, go to Cluster -> Capacity Provider -> Create -> Select your auto scaling group under Auto Scaling group.

Another tricky part is getting your service to use the instances (if you have a service running). You need to edit the Service, and change the Capacity provider strategy. Click on Add another provider and choose the new capacity provider you created in (2) above.

That's all! To ensure things are working properly: you should see your capacity provider under Graph -> Capacity Providers and you should see instances from your auto scaling group under Graph -> ECS Instances.

Upvotes: 1

cari
cari

Reputation: 2302

Well, i found out. Its all about the ecs-agent and its config file /etc/ecs/ecs.config (This file will be created through the Userdata field, when creating EC2 instances, even from an autoscaling configuration.) Read about its configuration options here: http://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-agent-config.html

But you can even copy a ecs.config stored on Amazon S3, do it like this (following lines go into Userdata field):

#!/bin/bash
yum install -y aws-cli
aws configure set default.s3.signature_version s3v4
aws configure set default.s3.addressing_style path
aws configure set default.region eu-central-1
aws s3 cp s3://<bucketname>/ecs.config /etc/ecs/ecs.config

note: Signature_version v4 is specific for some regions, like eu-central-1. This ofc only works, if your IAM role for the instance (in my case its ecsInstanceRole) has the right AmazonS3ReadOnlyAccess


The AWS GUI console way for that would be: Use the cluster wizard at https://console.aws.amazon.com/ecs/home#/firstRun . It will create an autoscaling grou for your cluster, a loadbalancer in front of it, and connect it all nicely.

Upvotes: 9

volker238
volker238

Reputation: 2260

I was struggling with this for a while. The key to getting the instances in the autoscaling group associated with your ECS cluster is in the user data. When you are creating your launch config when you get to step 3 "Configure Details" hit the advanced tab and enter a simple bash script like the following for your user data.

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

All the available parameters for agent configuration can be found here http://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-agent-config.html

Upvotes: 48

Samuel Karp
Samuel Karp

Reputation: 4682

An autoscaling group is not strictly associated to a cluster. However, an autoscaling group can be configured such that each instance launched registers itself into a particular cluster.

Registering an instance into a cluster is the responsibility of the ECS Agent running on the instance. If you're using the Amazon ECS-optimized AMI, the ECS Agent will launch when the instance boots and register itself into the configured cluster. However, you can also use the ECS Agent on other Linux AMIs by following the installation instructions.

Upvotes: 21

Related Questions