Skip to content

How to set CPU and Memory on Task level and Container level

0

I got the information to set my memory according to task level and to container level. I assume that on container level it is the cpu and memory from addContainer. But how to set cpu and memory on a task definition / level?

At the task level:

CPU: 6 vCPU (6144 CPU units in ECS)
Memory: 10 GB (10240 MiB in ECS)
At the container level:

CPU: 4 vCPU (4096 CPU units in ECS)
Memory: 4 GB (4096 MiB in ECS)

asked 2 years ago1.3K views

1 Answer
0

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:

  1. When creating a new task definition or updating an existing one, you'll need to specify the task-level CPU and memory values.

  2. For the CPU, you can specify it as vCPUs or CPU units. In your example, you'd set 6 vCPU or 6144 CPU units.

  3. 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:

  1. When adding a container to your task definition, you can specify the CPU and memory requirements for that specific container.

  2. 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:

  1. In the "Task size" section, you can set the task-level CPU and memory.
  2. 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

answered 2 years ago

EXPERT

reviewed 2 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.