Use Dockerfile for Lambda running ARM64 Architecture

0

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:

FROM public.ecr.aws/lambda/python:3.8

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

COPY lambda_function.py ./
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 /lambda-entrypoint.sh: exec format error",
  "errorType": "Runtime.InvalidEntrypoint"
}

Do I need to add an Entrypoint to my Dockerfile?

Thanks in advance

asked 2 years ago9547 views
2 Answers
2

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

profile pictureAWS
EXPERT
Uri
answered 2 years ago
profile picture
EXPERT
reviewed 23 days 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?

0

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 
 
phases: 
  install: 
    runtime-versions: 
      docker: 18 
  pre_build: 
    commands: 
      - echo Logging in to Amazon ECR... 
      - aws --version 
      - $(aws ecr get-login --region $AWS_DEFAULT_REGION --no-include-email) 
      - REPOSITORY_URI=$EcrRepo
      - COMMIT_HASH=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7)
      - IMAGE_TAG=${COMMIT_HASH:=latest}
  build: 
    commands: 
      - 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
  post_build:
    commands:
      - 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