Menu
Amazon Elastic Container Service
Developer Guide (API Version 2014-11-13)

Amazon ECS Task Placement Strategies

A task placement strategy is an algorithm for selecting instances for task placement or tasks for termination. For more information, see Amazon ECS Task Placement.

Strategy Types

Amazon ECS supports the following task placement strategies:

binpack

Place tasks based on the least available amount of CPU or memory. This minimizes the number of instances in use.

random

Place tasks randomly.

spread

Place tasks evenly based on the specified value. Accepted values are attribute key:value pairs, instanceId, or host. Service tasks are spread based on the tasks from that service.

Example Strategies

You can specify task placement strategies with the following actions: CreateService and RunTask.

The following strategy distributes tasks evenly across Availability Zones.

Copy
"placementStrategy": [ { "field": "attribute:ecs.availability-zone", "type": "spread" } ]

The following strategy distributes tasks evenly across all instances.

Copy
"placementStrategy": [ { "field": "instanceId", "type": "spread" } ]

The following strategy bin packs tasks based on memory.

Copy
"placementStrategy": [ { "field": "memory", "type": "binpack" } ]

The following strategy places tasks randomly.

Copy
"placementStrategy": [ { "type": "random" } ]

The following strategy distributes tasks evenly across Availability Zones and then distributes tasks evenly across the instances within each Availability Zone.

Copy
"placementStrategy": [ { "field": "attribute:ecs.availability-zone", "type": "spread” }, { "field": "instanceId", "type": "spread" } ]

The following strategy distributes tasks evenly across Availability Zones and then bin packs tasks based on memory within each Availability Zone.

Copy
"placementStrategy": [ { "field": "attribute:ecs.availability-zone", "type": "spread” }, { "field": "memory", "type": "binpack" } ]