---
title: "ECS unable to place a task: insufficient CPU or memory on EC2 | Proofline"
description: "Compare the new revision's CPU and memory reservation with each container instance's registeredResources and remainingResources."
url: https://proofline.sh/learn/ecs-unable-to-place-task-insufficient-resources/
---

[Learning center](/learn/)

# ECS unable to place a task: insufficient CPU or memory on EC2

Compare the new revision's CPU and memory reservation with each container instance's registeredResources and remainingResources. If the reservation is larger than every instance's registered total, the revision can never fit on this instance type. If it fits the registered total but not what remains, the cluster is full while old and new tasks run side by side.

Capacity overruns The Proofline team November 22, 2026 6 min read

## The event and the two causes behind it

On the EC2 launch type, a stalled deployment often shows this service event and no stopped task for the new revision, because ECS never placed one:

`service (service-name) was unable to place a task because no container instance met all of its requirements.`

When the closest candidate failed on CPU, the event adds `The closest matching container-instance container-instance-id has insufficient CPU units available.` A memory variant names memory in the same position. Both mean the same thing: the best instance ECS found did not have enough of that resource unreserved for this task. [Service event messages](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/service-event-messages-list.html)

Two causes produce that text during a deployment, and they need opposite fixes:

-   **The revision outgrew the instance type.** The new task definition reserves more CPU or memory than any container instance registered. Adding instances of the same type changes nothing.
-   **The cluster is full during the rollout.** The new task would fit on an empty instance, but every instance is occupied by old tasks. With the default `maximumPercent` of 200, ECS starts new tasks before it stops old ones, provided the cluster resources are available, so a cluster sized for one copy of the service has no room for the overlap. [Deployment configuration](https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_DeploymentConfiguration.html)

If you have not yet sorted the failure by layer, start from [the signature table](/learn/aws-deployment-failure-signatures/).

## Read what the revision reserves

Take the new deployment's exact task definition ARN from the service, then read its reservation. Use a read-only profile and replace the uppercase placeholders.

```
aws ecs describe-services \
  --profile PROFILE --region REGION --cluster CLUSTER --services SERVICE \
  --query 'services[0].{desired:desiredCount,config:deploymentConfiguration.{max:maximumPercent,min:minimumHealthyPercent},deployments:deployments[].{id:id,status:status,definition:taskDefinition,running:runningCount,pending:pendingCount},events:events[:10].[createdAt,message]}' \
  --output json --no-cli-pager

aws ecs describe-task-definition \
  --profile PROFILE --region REGION --task-definition TASK_DEFINITION_ARN \
  --query 'taskDefinition.{cpu:cpu,memory:memory,network:networkMode,containers:containerDefinitions[].{name:name,cpu:cpu,memory:memory,reservation:memoryReservation}}' \
  --output json --no-cli-pager
```

Run the second command for the old revision too. Work out each revision's reservation this way:

-   A task-level `cpu` or `memory` is what the task needs from an instance.
-   Without a task-level value, add the containers. For memory, a container's `memoryReservation` is subtracted from the instance's available memory when it is set; otherwise its `memory` is used.
-   CPU is in units, and an instance has 1,024 units for each vCPU.

[TaskDefinition fields](https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_TaskDefinition.html) · [ContainerDefinition memory and memoryReservation](https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_ContainerDefinition.html)

## Read what each instance registered and has left

`registeredResources` is the CPU and memory the agent offered to tasks when the instance registered, which is the most one instance can ever hold. `remainingResources` is what is not yet reserved by tasks on it now. [ContainerInstance fields](https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_ContainerInstance.html)

```
aws ecs list-container-instances \
  --profile PROFILE --region REGION --cluster CLUSTER \
  --query 'containerInstanceArns' --output json --no-cli-pager

aws ecs describe-container-instances \
  --profile PROFILE --region REGION --cluster CLUSTER \
  --container-instances CONTAINER_INSTANCE_ARN_1 CONTAINER_INSTANCE_ARN_2 \
  --query 'containerInstances[].{instance:ec2InstanceId,status:status,agent:agentConnected,running:runningTasksCount,cpuRegistered:registeredResources[?name==`CPU`].integerValue|[0],cpuLeft:remainingResources[?name==`CPU`].integerValue|[0],memRegistered:registeredResources[?name==`MEMORY`].integerValue|[0],memLeft:remainingResources[?name==`MEMORY`].integerValue|[0]}' \
  --output table --no-cli-pager
```

Registered memory is lower than the memory advertised for the instance type, because of platform overhead, kernel memory and any `ECS_RESERVED_MEMORY` set in the agent configuration. A task that asks for exactly the advertised amount cannot be placed. Compare against `memRegistered`, never against the instance type's specification. [Container instance memory](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/memory-management.html)

## What the comparison tells you

| New revision's reservation | Instances | Cause | What to change |
| --- | --- | --- | --- |
| Larger than `cpuRegistered` or `memRegistered` on every instance | Any | The revision does not fit this instance type | Reduce the reservation, or run the service on a larger instance type |
| Fits the registered total; larger than every `cpuLeft` or `memLeft` | Each runs old tasks | The cluster is full during the overlap | Add instances for the deployment, or let ECS stop old tasks first |
| Fits the remaining resources on some instance | Event still repeats | Something other than CPU or memory, or a stale event | Read the full event text for ports, attributes or the agent |

For the full-cluster case, the deployment configuration decides whether ECS can make room itself. With `minimumHealthyPercent` at its default of 100, the scheduler must keep the full desired count running, so it waits for capacity. A lower value lets it stop some old tasks before starting new ones, at the cost of running fewer tasks during the rollout. The minimum is rounded up and the maximum rounded down. [Rolling update deployments](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/deployment-type-ecs.html) · [Deployment configuration bounds](/learn/ecs-deployment-configuration-blocks-replacement/)

## An illustrative fixture: same event, two causes

This fixture is fictional. The service `orders` runs six tasks of `orders:57` on three container instances. Each instance registered 2,048 CPU units and 3,828 MiB of memory. `orders:57` reserves 512 CPU units and 1,536 MiB, two tasks per instance. The deployment runs with `maximumPercent` 200 and `minimumHealthyPercent` 100.

In the first case `orders:58` raises task memory to 4,096 MiB:

| Instance | memRegistered | memLeft | Fits 4,096 MiB? |
| --- | --- | --- | --- |
| i-0a1 | 3,828 | 756 | No, even when empty |
| i-0b2 | 3,828 | 756 | No, even when empty |
| i-0c3 | 3,828 | 756 | No, even when empty |

No instance of this type can ever hold the task. Scaling the cluster out adds more instances that also cannot hold it. Roll back to `orders:57`, then either bring the memory back under 3,828 MiB or move the service to capacity with larger instances.

In the second case `orders:58` reserves 2,048 MiB. Each instance still has only 756 MiB left, because two old tasks hold 3,072 MiB. The task fits an empty instance, so the cluster is short of room only while both revisions run. One added instance lets ECS place a new task, after which it can stop an old one and continue. Setting `minimumHealthyPercent` to 50 would instead let ECS stop up to three old tasks first, freeing room on existing instances while the service runs at half its desired count.

## Confirm on the replacement

After the change, the event should stop repeating and the service should report `service (service-name) has reached a steady state.` Check that each new task has a `containerInstanceArn` and that its `taskDefinitionArn` is the revision you meant. Then read `remainingResources` again: an instance left with only a few MiB means the next deployment will hit the same wall. [Service event messages](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/service-event-messages-list.html)

```
aws ecs describe-tasks \
  --profile PROFILE --region REGION --cluster CLUSTER --tasks TASK_ARN_1 TASK_ARN_2 \
  --query 'tasks[].{task:taskArn,definition:taskDefinitionArn,status:lastStatus,host:containerInstanceArn,deployment:startedBy}' \
  --output table --no-cli-pager
```

## Where the reading misleads

The event names one closest matching instance, not every instance ECS rejected. Task placement constraints are binding and can prevent placement, so an instance with free memory can still be excluded by a constraint. Read the service's `placementConstraints` if the numbers say a task should fit. [Task placement](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-placement.html)

`remainingResources` is a snapshot. By the time you read it, ECS may have stopped tasks or the deployment may have rolled back, so a free instance now does not show that one was free at the failure. The service keeps its 100 most recent events, and the archived developer guide says duplicate messages are omitted until the cause is resolved or six hours pass, so the event may appear once for a long stall. [describe-services](https://docs.aws.amazon.com/cli/latest/reference/ecs/describe-services.html)

The same opening sentence covers other shortages with their own fixes: a host port already in use, too few ENI attachment points for `awsvpc` tasks, a missing required attribute, and an instance whose agent is disconnected. For ports, see [the host port guide](/learn/ecs-host-port-conflict-during-deploy/); for the agent, see [the agent guide](/learn/ecs-container-instance-agent-disconnected/). With an Auto Scaling group capacity provider, a task larger than the smallest instance type in the group does not trigger scale-out at all; see [tasks stuck in PROVISIONING](/learn/ecs-capacity-provider-tasks-stuck-provisioning/). [Managed scaling behavior](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/managed-scaling-behavior.html)

## Questions

### Why does ECS say insufficient memory when the instance has free memory?

ECS compares the task's reservation with the memory not yet reserved by other tasks, not with memory actually in use. Containers that reserve more than they use still hold that reservation, and registered memory is already lower than the instance type's advertised size.

### Will adding container instances fix an insufficient CPU or memory event?

Only when the cluster is full. If the new revision reserves more than any instance registered, more instances of the same type cannot hold it; reduce the reservation or use a larger instance type.

### Why does the placement error appear only during deployments?

A rolling deployment with `maximumPercent` above 100 starts new tasks while old ones still hold their reservations. A cluster sized for one copy of the service has no room for that overlap, even though the same tasks fit once the old ones stop.

## One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. [Eligibility and fair-use terms](/free-code-review/).

[Start free with GitHub](https://proofline.sh/orgs/plan?offer=free_month)

## Related reading

-   ### [ECS deploy stuck: the new task needs a host port the old task holds](/learn/ecs-host-port-conflict-during-deploy/)
    
    Capacity overruns The Proofline team November 22, 2026 6 min read
    
-   ### [ECS unable to stop or start tasks: deployment configuration bounds](/learn/ecs-deployment-configuration-blocks-replacement/)
    
    Deployment failures The Proofline team November 22, 2026 7 min read
