skip to Main Content

I try to execute an ECS task from a lambda function, the task is created successfully but when the execution starts shortly after the task stops and in Container details shows a message saying: Exit code: 1 .

When the message ends in the log list it says:
exec /usr/local/bin/python3: exec format error.
but I don’t understand why, the local image works fine. I try to see if it is a policy or role issue but it doesn’t seem to be the solution.

enter image description here

I don’t think it’s the image because if I run it locally it works, but I’m running out of possibilities.

I’m also trying to see now if it’s an AWS permissions issue.

2

Answers


  1. When the message ends in the log list it says: exec /usr/local/bin/python3: exec format error.

    This means you either deployed an X86 image to an ARM server (like AWS Fargate Graviton), or you deployed an ARM image (like an image built on an M1 Mac) to an X86 server.

    Login or Signup to reply.
  2. Thanks to @mark-b giving me the right answer!

    This means you either deployed an X86 image to an ARM server (like AWS Fargate Graviton), or you deployed an ARM image (like an image built on an M1 Mac) to an X86 server.

    I built a very simple node.js docker image on my M1 Mac, and I tried to deploy via ECS.
    He was right. I had to set the runtime platform values correctly. The ECS task keeps stopping with Exit Code 1.

    In this doc the value cpuArchitecture could be set ARM64. If you built the docker image on M1 Mac, you have to set like that. My issue solved.

    If you are using the terraform, the code below would be helpful:

    resource "aws_ecs_task_definition" "example_task" {
      family = "example_family"
    
      // Fargate is a type of ECS that requires awsvpc network_mode
      requires_compatibilities = ["FARGATE"]
      network_mode             = "awsvpc"
    
      // Valid sizes are shown here: https://aws.amazon.com/fargate/pricing/
      memory = "512"
      cpu    = "256"
      # if you use X86_64, you will be trapped in "Exit code: 1" hell
      runtime_platform {
        operating_system_family = "LINUX"
        cpu_architecture        = "ARM64"
      }
    
      // Fargate requires task definitions to have an execution role ARN to support ECR images
      execution_role_arn = aws_iam_role.ecs_role.arn
    
      container_definitions = <<EOT
    [
        {
            "name": "example_container",
            "image": "<ecr repo url>/example-app:latest",
            "memory": 512,
            "essential": true,
            "portMappings": [
                {
                    "protocol": "tcp",
                    "containerPort": 3000,
                    "hostPort": 3000
                }
            ]
        }
    ]
    EOT
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search