Example Amazon ECS task placement constraints - Amazon Elastic Container Service
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Example Amazon ECS task placement constraints

The following are task placement constraint examples.

This example uses the memberOf constraint to place tasks on t2 instances. It can be specified with the following actions: CreateService, UpdateService, RegisterTaskDefinition, and RunTask.

"placementConstraints": [ { "expression": "attribute:ecs.instance-type =~ t2.*", "type": "memberOf" } ]

The example uses the memberOf constraint to place replica tasks on instances with tasks in the daemon service daemon-service task group, respecting any task placement strategies that are also specified. This constraint ensures that the daemon service tasks get placed on the EC2 instance prior to the replica service tasks.

Replace daemon-service with the name of the daemon service.

"placementConstraints": [ { "expression": "task:group == service:daemon-service", "type": "memberOf" } ]

The example uses the memberOf constraint to place tasks on instances with other tasks in the databases task group, respecting any task placement strategies that are also specified. For more information about task groups, see Group related Amazon ECS tasks . It can be specified with the following actions: CreateService, UpdateService, RegisterTaskDefinition, and RunTask.

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

The distinctInstance constraint places each task in the group on a different instance. It can be specified with the following actions: CreateService, UpdateService, and RunTask

"placementConstraints": [ { "type": "distinctInstance" } ]