We're using Amazon ECS for our services. We have a cluster called application
and within that cluster, we have several services:
- dev_app
- dev_kafka
- dev_zookeeper
- qa_app
- qa_kafka
- qa_zookeeper
- etc.
And the services pull from task definitions that have correlating constraints, i.e., memberOf(attribute:env == qa), memberOf(attribute:role == zookeeper)
We launch our instances via EC2 launch configurations + Autoscaling Groups. This means that our services can't actually auto-scale right now, because instances launch without the appropriate attributes. The only way I know how to add the attributes currently is to wait for the instance to be added to the application
cluster, and go in to manually add custom attributes to each instance.
The question: Can I somehow add instance attributes via the launch configuration, or some other means, at launch?
I've found modify-instance-attribute
, but this only seems to be valid for existing attributes, not custom attributes. I've also tried put-attributes
, but this seems to only be valid for ECS resources (my instance ARN is apparently invalid).
Use "user data" in launch configuration.
echo ECS_INSTANCE_ATTRIBUTES={\"mycostomattr\":\"myvalue\"} >> /etc/ecs/ecs.config
See http://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-agent-config.html
If we are using single agent configuration variable like cluster name, then we use below syntax in user data.
#!/bin/bash
echo "ECS_CLUSTER=MyCluster" >> /etc/ecs/ecs.config
But if we have multiple variable to write to /etc/ecs/ecs.config use the below format.
#!/bin/bash
cat <<'EOF' >> /etc/ecs/ecs.config
ECS_CLUSTER=MyCluster
ECS_ENGINE_AUTH_TYPE=docker
ECS_LOGLEVEL=debug
EOF
In cloudformation, instance user-data we have to apply
"#!/bin/bash -xe\n",
"cat <<'EOF' >> /etc/ecs/ecs.config \n",
"ECS_CLUSTER=", { "Ref": "MyCluster" },
"\n",
"ECS_LOGLEVEL=debug\n",
"ECS_ENGINE_AUTH_TYPE=docker\n",
"EOF"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With