aws / aws-lambda-base-images

Apache License 2.0
670 stars 110 forks source link

Launch error: fork/exec /lambda-entrypoint.sh: exec format error #61

Open p4tr1ckc4rs0n opened 2 years ago

p4tr1ckc4rs0n commented 2 years ago

I'm building a lambda base image on apple M1 via the SAM template like so:

Metadata:
      DockerBuildArgs:
        platform: linux/amd64
      DockerTag: docker-tag-123
      DockerContext: ../../
      Dockerfile: path/to/Dockerfile

Building and deploying the stack along with the lambda docker image is fine however I get this error when invoking the function:

Launch error: fork/exec /lambda-entrypoint.sh: exec format error 

I suspect this is an issue with the platform because when i run the image locally (on my apple M1) with the --platform set to "linux/amd64" it errors with the following:

docker: Error response from daemon: image with reference docker-tag-123 was found but does not match the specified platform: wanted linux/amd64, actual: linux/arm64/v8.

How do I get SAM to build a docker image as linux/amd64 or at least respect the DockerBuildArgs? Also where are the docs for the Metadata section?

justinmk3 commented 2 years ago

Also where are the docs for the MetaData section?

Good question. I would expect it to be in https://github.com/aws/serverless-application-model/blob/master/versions/2016-10-31.md but I don't see it there. Probably because Metadata is a generic feature of CloudFormation templates: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/metadata-section-structure.html which then implies that SAM has extended its format informally.

Here are the docs I found for SAM CLI Metadata: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-using-build.html

p4tr1ckc4rs0n commented 2 years ago

I "solved" this by pulling the following base image that is specific to my target architecture (linux/amd64) and specifying that in my Dockerfile.

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

Couldn't figure out how to get SAM to respect DockerBuildArgs 🤷 .

Thanks for the documentation links - nothing on DockerBuildArgs though :(.