Use Dockerfile for Lambda running ARM64 Architecture


I have a function that I wrote and am trying to get it to run on the ARM64 version of Lambda. It works fine on the x86 version. I have not been able to find anything online regarding needing to do something special for an ARM64 Dockerfile.

My Dockerfile is:


COPY requirements.txt .
RUN pip install -r requirements.txt && rm requirements.txt

COPY values.txt ./
CMD [ "lambda_function.lambda_handler" ]

I am coding/building the Dockerfile on a Lenovo Laptop running Ubuntu if that matters. When I try to test the function, it exits nearly immediately and gives an error:

  "errorMessage": "Error: fork/exec / exec format error",
  "errorType": "Runtime.InvalidEntrypoint"

Do I need to add an Entrypoint to my Dockerfile?

Thanks in advance

asked 2 years ago9981 views
2 Answers

See here: Just append -arm64 to the base image name.

profile pictureAWS
answered 2 years ago
profile picture
reviewed 2 months ago
  • Thank you. I am trying to build the image and I get an error when it tries to install the PIP packages:

    [Warning] The requested image's platform (linux/arm64/v8) does not match the detected host platform (linux/amd64) and no specific platform was requested standard_init_linux.go:228: exec user process caused: exec format error

    I tried running the build command like: docker build -t IMAGENAME . --platform linux/arm64 But it still gives me the same error.

    Is there a special way I have to build the image?


Yes you could append the host platform on it. But the issue is a difference between where you build the image and the Architecture setting on the lambda.

Example: if you build the image on an m1 mac push to ECR and set the Architecture setting to x86_64 then you will get this error.

You can either change the setting in lambda or if you are working with multiple people on different systems Id suggest using CodePipeline with a CodeBuild step and you can define the system the pipeline builds on so every-time the build is consistent with a buildspec.yaml like this.

version: 0.2 
      docker: 18 
      - echo Logging in to Amazon ECR... 
      - aws --version 
      - $(aws ecr get-login --region $AWS_DEFAULT_REGION --no-include-email) 
      - REPOSITORY_URI=$EcrRepo
      - IMAGE_TAG=${COMMIT_HASH:=latest}
      - echo Build started on `date` 
      - echo Building the Docker image... 
      - docker build -t $REPOSITORY_URI:latest .
      - docker tag $REPOSITORY_URI:latest $REPOSITORY_URI:$IMAGE_TAG
      - echo Build completed on `date`
      - echo Pushing the Docker images...
      - docker push $REPOSITORY_URI:latest
      - docker push $REPOSITORY_URI:$IMAGE_TAG
      - aws lambda update-function-code --function-name [YOUR_FUNCTION_NAME] --image-uri $REPOSITORY_URI:$IMAGE_TAG
answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions