amazon-ecs-cli icon indicating copy to clipboard operation
amazon-ecs-cli copied to clipboard

compose up - reason=RESOURCE:MEMORY

Open spenoir opened this issue 10 years ago • 17 comments

Not sure if this an issue with amazon-ecs-cli as it could be my config. INFO[0000] Couldn't run containers reason=RESOURCE:MEMORY

when running ecs-cli compose up.

Is this because of a docker-compose misconfig? I don't get this problem when runnning docker-compose up locally. What exactly is a resource in this context? I'm thinking it could be due to mem_limit being set wrong in docker-compose.yml

spenoir avatar Nov 02 '16 22:11 spenoir

Hi, I have the same error. How did you fixe it ?

fungiboletus avatar Nov 09 '16 10:11 fungiboletus

Oh ok, mem_limit must be defined for amazon-ecs.

fungiboletus avatar Nov 09 '16 10:11 fungiboletus

I have the same issue and I'm still looking for a solution. And so.. I think you should choose another instance type. For example: more than t2.micro (there is limited resources in the type).

SmithWebster avatar Dec 07 '16 14:12 SmithWebster

The default value is 512 MB. Also, ecs-cli compose seems to require that mem_limit is written in bytes. So for 128 MB, write

  mem_limit: 134217728

jrc avatar Jan 08 '17 16:01 jrc

I'm setting mem_limit, but the error still won't go away. What else could cause this?

dannymcpherson avatar Feb 03 '17 15:02 dannymcpherson

@dannymcpherson Do you have sufficient memory available on your container instances? Try reducing the mem_limit value, and see if that works.

tefla avatar Feb 06 '17 13:02 tefla

I had the error Encountered error starting new ECS task: { "failures": [ { "reason": "RESOURCE:MEMORY", "arn": "arn:aws:ecs:us-east-1:xxxxxxxxxxxx:container-instance/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" } ], "tasks": [] } from trying to run an elastic beanstalk app. Turned out this was because the sum of the memory I allocated for each container was > the memory of the EC2 box.

jborrey avatar Feb 07 '17 09:02 jborrey

Also might be useful: https://rossfairbanks.com/2015/03/31/hello-world-in-ec2-container-service.html

jborrey avatar Feb 07 '17 09:02 jborrey

I discovered the other day that my EB config was set to t1.micro instead of t2.micro, which is why I didn't have the 1 GB that I thought I had. You might want to double-check your config against the specs on https://aws.amazon.com/ec2/instance-types/

eb ssh then sudo docker stats will tell you how much memory each container is using.

jrc avatar Feb 07 '17 09:02 jrc

That was my problem @jborrey. For future readers, without specifying a mem_limit on my docker-compose file, ecs defaulted to 512MB for each containers, and my docker-compose consists of 3 containers, so it ended up declaring 1.5GB of RAM. That amount of RAM was not available on a t2.micro instance, hence the error message. Then I set limits on my containers and ended up with my MYSQL service crashing with ~300MB. Still investigating if this is normal consumption for MYSQL, but in the meantime I think I'll need a more powerful instance.

leoskyrocker avatar Jun 08 '17 03:06 leoskyrocker

You can also specify the mem_limit in kilobytes. Like this:

mem_limit: 3576492k

This problem was driving me crazy. Thanky the lordy for this thread. 🙏

jasonrhaas avatar Sep 01 '17 01:09 jasonrhaas

I fixed it inthe task definition .json file

{
  "family": "..",
  "containerDefinitions": [
    {
      "name": "..",
      "image": "...",
      "cpu": 1,
      "memory": 500, # Set this to whatever in MB

stoicskyline avatar Feb 27 '18 03:02 stoicskyline

I was facing this problem with RESOURCE:MEMORY and I couldn't figure out why my mem_limit parameter was not being picked up by ecs-cli however I found out that my file format missed the task_definition key, so make sure you specify it:

Wrong:

version: "3"
  services:
    judge-server:
      mem_limit: "128m"
    oj-backend:
      mem_limit: "128m"

Right:

version: "3"
task_definition:  # <==== Services must be defined under task_definition key
  services:
    judge-server:
      mem_limit: "128m"
    oj-backend:
      mem_limit: "128m"

motatoes avatar Aug 12 '18 09:08 motatoes

I still have this issue, and I cannot figure out why it's failing for me.
I want to run 3 docker containers in one EB environment, on t2.medium instances.

Dockerrun.aws.json:

{
  "AWSEBDockerrunVersion": 2,
  "containerDefinitions": [
    {
      "name": "web-app",
      "image": "...",
      "command": [...],
      "essential": true,
      "memory": 1000,
      "mountPoints": [...]
    },
    {
      "name": "channels-app",
      "image": "...",
      "command": [...],
      "essential": true,
      "memory": 1000,
      "mountPoints": [...]
    },
    {
      "name": "nginx",
      "image": "...",
      "command": [...],
      "essential": true,
      "memory": 500,
      "mountPoints": [...]
    }
  ]
}

So 1G+1G+500M = 2.5G of memory. I ssh'ed into the allocated t2.medium instance, and there is enough free memory available: MemFree: 3518368 kB (3.5G).

Why do I still get the error every time?

Encountered error starting new ECS task: {
    "failures": [
        {
            "reason": "RESOURCE:MEMORY", 
            "arn": "arn:aws:ecs:eu-central-1:XXX:container-instance/XXX"
        }
    ], 
    "tasks": []
}

I tried running with t2.large, that works. But it's too expensive, and medium should be enough!

yspreen avatar Oct 24 '18 13:10 yspreen

This took me many days to figure out, so for everyone with the same issue:

Check your deployed app! Apparently eb cli ignores all uncommited changes when working in a git repo. I was permanently changing parameters, running eb deploy, but did not notice that the zip file generated did not include the changes. Only the last commit in your current branch will be deployed!

TL;DR: My old config was deployed to eb and all changes I tried for fixing did not stick.

yspreen avatar Oct 24 '18 13:10 yspreen

Even I am facing the same issue. I am triggering ECSOperator() tasks from Airflow ie. ECS tasks are triggered from Airflow. What I noticed is when ever a ECS task failed with this error, the Airflow CPU and Memory utilisation peaks up. And also I don't see any exceptions in CloudWatch pertaining to the RESOURCE:MEMORY. Is this memory issue related to Airflow or the ECS container where the task is running ?

K-7 avatar Apr 22 '20 07:04 K-7

memory

yeah this is what worked I was using a t2 micro instance and the limits in my task were way more than I had in the instance so I reduced it and it worked

PranjalChaitanya avatar Sep 08 '22 15:09 PranjalChaitanya