27

I'm trying to set up CI with AWS ECS and docker. I use Codeship as a CI tool, but that should not really matter much.

I do the following steps in a shell script:

  • build an image with my Dockerfile,
  • push the image to ECS repository,
  • push a task-definition.json to ECS aws ecs register-task-definition --family postgraphile --cli-input-json file:///deploy/ecs-task-def.json --region us-east-2
  • run the ECS task aws ecs run-task --task-definition postgraphile --cluster testcluster --region us-east-2

Shell script runs successfully, however I see an error in output after I try to run my ECS task:

{
    "tasks": [],
    "failures": [
        {
            "arn": "arn:aws:ecs:us-east-2:99999999999:container-instance/050ab165-7669-45d5-8be7-d990cf4fff42",
            "reason": "RESOURCE:MEMORY"
        }
    ]
}

my ecs-task-def.json:

{
  "containerDefinitions": [
    {
      "name": "postgraphile-container",
      "image": "999999999999.dkr.ecr.us-east-2.amazonaws.com/test-repository",
      "memory": 500,
      "essential": true,
      "portMappings": [
        {
          "hostPort": 5000,
          "containerPort": 5000
        }
      ]
    }
  ],
  "volumes": [],
  "memory": "900",
  "cpu": "128",
  "placementConstraints": [],
  "family": "postgraphile",
  "taskRoleArn": ""
}

I think I already checked all the memory limits.. am I missing anything?

UPDATE: After couple of reboots of ec2 instance I can finally run the ecs task with no errors. After running task several times, the error returns

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
Vic
  • 645
  • 1
  • 7
  • 18
  • 23
    In my case, this occurred because my EC2 instance had less memory than I had specified in my container. I was able to find the details in the Events tab in my service (ECS > Cluster > Service > Events). – cklab Mar 23 '18 at 17:14
  • 1
    Did you ever find out how to tell "aws ecs run-task" to run an instance on your cluster with enough memory to run the task? – grayaii Jun 15 '18 at 14:18
  • 1
    yes, everything is ok with task definition. My problem was: I tried to run the task, when there already was a running task. So as i want to just restart a running task, I actually have to stop the running task and run it again using the same task definition – Vic Jun 20 '18 at 10:22
  • 1
    In my case, I wanted 8 Go so I wrote memory: 8000000, but the memory is in megabytes so I needed 8000 (7800 exactly). – Bilow Jan 10 '20 at 10:48
  • 1
    @cklab thank you friend. i updated the EC2 instance type for one more small, but my elastic beanstalk application stopped working. so the reason was exactly the thing that you said: "my EC2 instance had less memory than I had specified in my container"... thank you ! – Carlos Andres May 28 '20 at 05:09

3 Answers3

1

There are limited values accepted for CPU and memory. Check the docs for the supported values:

CPU value Memory value (MiB)
256 (.25 vCPU) 512 (0.5GB), 1024 (1GB), 2048 (2GB)
512 (.5 vCPU) 1024 (1GB), 2048 (2GB), 3072 (3GB), 4096 (4GB)
1024 (1 vCPU) 2048 (2GB), 3072 (3GB), 4096 (4GB), 5120 (5GB), 6144 (6GB), 7168 (7GB), 8192 (8GB)
2048 (2 vCPU) Between 4096 (4GB) and 16384 (16GB) in increments of 1024 (1GB)
4096 (4 vCPU) Between 8192 (8GB) and 30720 (30GB) in increments of 1024 (1GB)

https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-cpu-memory-error.html

palvarez
  • 1,508
  • 2
  • 8
  • 18
0

I was getting this error when deploying a service on an ECS cluster. Removing the service completely and then redeploying it afresh helped me resolve this issue.

abhijain
  • 11
  • 3
0

I had faced similar error while deploying services to EC2 using docker. I was using putty not CLI. I ran command docker images to get the size of each image. I found total size was more than my EC2 instance storage. I increased the EC2 instance volume to 20GB (EC2-->Volume-->Modify volume). Issue was resolved. Later I faced issue again after multiple trial and error. This time, I found I had lot of unused images which got accumulated after multiple docker compose commands. I removed all the containers, volumes and images and memory error was resolved.

Sajin Pattath
  • 241
  • 3
  • 5