Search code examples
c#amazon-web-servicesdockeramazon-ecs

Allocate configuration for the cluster in ECS, where each instance receives a unique value


I need to simulate an array of devices in ECS (Fargate), where each device has a dedicated MAC. I have a list of MACs to create a cluster from.

So far I managed to build a C# app and dockerize it, that simulates my device. I am able to create a cluster, by specifying it as a service in TaskDefinition, and specyfing Desired tasks to be of the number of devices I need. Then I created an array in Systems Manager, Parameter Store, where I specify the array of MAC addresses.

This all works fine, but I can't seem to find any index of the instance or similar in the env of the container, to be able to allocate single MAC out of the given array for each instance. Instance has ECS_CONTAINER_METADATA_URI and I am able to query it and get for example DockerId which seems to be unique, but it is guid and not just an index.

I could build a separate service that accounts for all such ids and allocates MACs by those ids, but it sounds too complex. I am sure there has to be a way to indexize instances, given that I am running the fixed number of them in a cluster (no auto-scaling). How can I do that?


Solution

  • I could build a separate service that accounts for all such ids and allocates MACs by those ids, but it sounds too complex.

    This is what I would do. It wouldn't be that complex.

    I am sure there has to be a way to indexize instances, given that I am running the fixed number of them in a cluster (no auto-scaling). How can I do that?

    If you are just starting an ECS service with a desired count setting, there really isn't any way to have an index number automatically assigned to those instances by ECS.

    If you are using the ECS run-task command once for each instance, in a for loop or something, then in that loop you could pass an index value as an environment variable for each task, via the Container Override attribute.