By using AWS re:Post, you agree to the Terms of Use

ECS Task Groups

0

I'm trying to set some anti-affinity for my tasks, and looking at the AWS docs and this nifty article, task groups is the way to go:

https://aws.amazon.com/blogs/compute/amazon-ecs-task-placement/

Trouble is, I can't seem to find my task groups. According to the docs, if my tasks were launched by the service scheduler, the task group name is the same as the service:

https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-placement-constraints.html#task-groups
https://docs.aws.amazon.com/AmazonECS/latest/developerguide/cluster-query-language.html

However, if I query for instances that match that particular task group, I'm returned with 0 instances:

aws ecs list-container-instances --cluster dev --filter "task:group == workflow"
{
    "containerInstanceArns": []
}

Even though I'm quite certain I have that service, and that there are multiple instances of that task running:

aws ecs list-services --cluster dev
{
    "serviceArns": [
        "arn:aws:ecs:eu-west-1:1234567890123:service/dev/workflow",
        ...
    ]
}

What am I missing?

asked 3 years ago72 views
2 Answers
0

Hi
The only thing I think you're missing is that the default task group for an ECS service is in fact service:<service name>.
So for your example, you would need to provide the filter as follows:

aws ecs list-container-instances \
      --cluster dev \
      --filter "task:group == service:workflow"

On top of that, I would also double check that you do indeed have tasks running in that service. Otherwise, you'll see the above give the same empty list as an output.

Once you get a hang of the query languge, anti-affinity can be found using the not keyword as follows:

aws ecs list-container-instances \
      --cluster dev \
      --filter "not(task:group == service:workflow)"

Additionally, the task group for a single task can be overidden when running the task via the RunTask API. In the case where no task group set with RunTask, the default is family:<task definition family>.

Hope this helps. Let me know if you have any further questions.

answered 3 years ago
0

Thanks @fortejas-amazon, that was exactly it. Re-reading the documentation it makes perfect sense now.

When you launch a task using the RunTask or StartTask action, you can specify the name of the task group for the task. If you don't specify a task group for the task, the default name is the family name of the task definition (for example, family:my-task-definition).

For tasks launched by the service scheduler, the task group name is the name of the service (for example, service:my-service-name).

I was confused by the examples which show this:

"placementConstraints": [
    {
        "expression": "task:group == databases",
        "type": "memberOf"
    }
]

Which I understand now, would be for explicitly named task groups.

answered 3 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions