resource:memory error when trying to run an ECS ta

2020-08-11 11:02发布

问题:

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