-4

I have this error, it shows the error CPU is not correct

Error: creating ECS Task Definition (wb_td): ClientException: Invalid 'cpu' setting for task.

with this source below.

resource "aws_ecs_task_definition" "this" {
  family                   = var.ecs_task_name
  network_mode             = "awsvpc"
  requires_compatibilities = ["FARGATE"]
  cpu                      = 1
  memory                   = 512
 #execution_role_arn       = aws_iam_role.ecs_execution.arn
 #task_role_arn            = aws_iam_role.ecs_task.arn
    
  container_definitions = jsonencode([{
    name      = "first"
    image     = "service-first"
    memory    = 128
    essential = true
    portMappings = [
      {
         containerPort = 80
         hostPort      = 80
      }
    ]
    },
    {
       name      = "second"
       image     = "service-second"
       memory    = 128
       essential = true
       portMappings = [
         {
           containerPort = 443
           hostPort      = 443
         }
       ]
     }
  ])
    
  tags = {
    Name = var.ecs_task_name
  }
}

1 Answer 1

3

I think you are using a wrong CPU/memory combination. The full list is defined in the AWS docs. Based on this terraform code:

  cpu    = 1
  memory = 512

It should be switched to either cpu = "256" (if you want to keep 512MB of memory):

  cpu    = "256"
  memory = "512"

If you still want to have 1vCPU, then you need more memory, starting with 2GB minimum. In that case that should be defined as:

  cpu    = "1024"
  memory = "2048"

Fargate Tasks

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.