- Newest
- Most votes
- Most comments
You're correct in your understanding of setting CPU and memory at the container level using the addContainer method. For setting CPU and memory at the task definition level, you need to specify these values when creating or updating the task definition itself.
To set CPU and memory at the task level:
-
When creating a new task definition or updating an existing one, you'll need to specify the task-level CPU and memory values.
-
For the CPU, you can specify it as vCPUs or CPU units. In your example, you'd set 6 vCPU or 6144 CPU units.
-
For memory, you specify it in MiB or GB. In your case, you'd set 10 GB or 10240 MiB.
These task-level resources represent the total amount available to be shared among all containers in the task.
For the container level:
-
When adding a container to your task definition, you can specify the CPU and memory requirements for that specific container.
-
In your example, you'd set 4 vCPU (or 4096 CPU units) for CPU and 4 GB (or 4096 MiB) for memory.
It's important to note that the sum of container-level resource allocations should not exceed the task-level resources. In your example, the task has 6 vCPU and 10 GB memory, while the container is allocated 4 vCPU and 4 GB memory, which is within the task's limits.
When using the Amazon ECS console to create a task definition:
- In the "Task size" section, you can set the task-level CPU and memory.
- In the "Container definitions" section, you can set the container-level CPU and memory for each container.
If you're using AWS CLI or SDKs, you would include these values in the appropriate fields of your task definition JSON or API calls.
Remember that for Fargate tasks, there are specific supported combinations of CPU and memory values, while for EC2 tasks, you have more flexibility in choosing these values.
Sources
Amazon ECS task definition parameters - Amazon Elastic Container Service
Creating an Amazon ECS task definition using the console - Amazon Elastic Container Service
Relevant content
asked 2 years ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated a year ago
