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

질문됨 2년 전9535회 조회
2개 답변
2

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

profile pictureAWS
전문가
Uri
답변함 2년 전
profile picture
전문가
검토됨 22일 전
  • 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
답변함 2년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠