ECS: no container instance met all of its requirements

,

We have an ECS cluster with 3 EC2 instances. In this cluster we have a bunch of services running, all separate apps with 1 task.

Frequently when I try to run a new service, ECS tries to run the task in an EC2 instance with not enough memory/CPU, while there is a different instance available with more than enough. In fact, there are now 2 instances with both 5 tasks, and 1 instance with only 1.

What could be the reason of this weird division of tasks? I’ve tried every possible task placement strategy but that doesn’t seem to make a difference. Or perhaps task placement is only relevant for multiple tasks from the same service? That still doesn’t explain why it won’t just run on an instance that does have enough memory.

Thanks for your suggestions!

Edit: this has been a recurring issue, and is not related to the outages at the time of posting a.f.a.i.k.


Related discussions:

If this is specific to today you can probably scan the front page to get an idea. If not, would be good to clarify just cause today was a bit noisy.

Did you define cpu and memory at the task level?

In the task definition indeed

The task placement strategies use different criteria for determining where to place the task. The binpack strategy does exactly what you’re seeing, but not what you want. It intentionally places more tasks on one instance, rather than spreading them evenly.

I think if you want to get the tasks to spread evenly, you can use the following strategy,

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

but I also don’t think this will work perfectly such that you will have an even distribution all the time. If you’re seeing issues running out of memory, just create more instances :slight_smile: using either autoscaling or by setting a higher number of desired instances. 3 instances is a low number anyways, I’d recommend 9 for availability purposes, if you can afford it.

Hello, makeswell2: code blocks using backticks (```) don’t work on all versions of Reddit!

Some users see

/ this instead.

To fix this, indent every line with 4 spaces instead. It’s a bit annoying, but then your code blocks are properly formatted for everyone.

An easy way to do this is to use the

. If it’s not working, try switching to the fancy-pants editor and back again.

Comment with formatting fixed for old.reddit.com users

FAQ

^(You can opt out by replying with backtickopt6 to this comment.)