Reputation: 3548
I've built an image for Lambda using public.ecr.aws/lambda/python:3.8
but always get this error.
Tried changing up the function and file names, but not getting any more details for debugging.
Also I've run the function locally and the entrypoint/cmd works.
START RequestId: cb4ba88c-c347-4e7d-b1ca-031a2e02fde4 Version: $LATEST
IMAGE Launch error: fork/exec /lambda-entrypoint.sh: exec format error Entrypoint: [/lambda-entrypoint.sh] Cmd: [index.lambda_handler] WorkingDir: [/var/task]IMAGE Launch error: fork/exec /lambda-entrypoint.sh: exec format error Entrypoint: [/lambda-entrypoint.sh] Cmd: [index.lambda_handler] WorkingDir: [/var/task]END RequestId: cb4ba88c-c347-4e7d-b1ca-031a2e02fde4
REPORT RequestId: cb4ba88c-c347-4e7d-b1ca-031a2e02fde4 Duration: 12.86 ms Billed Duration: 13 ms Memory Size: 128 MB Max Memory Used: 3 MB
RequestId: cb4ba88c-c347-4e7d-b1ca-031a2e02fde4 Error: fork/exec /lambda-entrypoint.sh: exec format error
Runtime.InvalidEntrypoint
Upvotes: 29
Views: 14540
Reputation: 9523
As Jeremy said, this is an architecture issue. If you are using Serverless Framework on an M1 machine, you can solve that by specifying the platform
option for the docker image:
provider:
name: aws
ecr:
images:
image_name:
platform: linux/amd64
Further reading about this option can be found here.
Upvotes: 3
Reputation: 14438
For those weary travellers using Serverless framework and experiencing similar issues...
I had the same for nodejs and docker on Mac M1 using the standard aws-nodejs-docker-demo
.
To Jeremy's point above, yes you can also simply add architecture: arm64
to serverless.yml to change the lambda architecture. Arm should be sightly cheaper too.
provider:
name: aws
region: ap-southeast-2
architecture: arm64
ecr:
uploaded to ECR
images:
appimage:
path: ./
You should then see the function version switch architecture from x86_64 to arm64
Upvotes: 6
Reputation: 3548
Turned out to be an architecture compatibility issue -
Needed to make sure the arch matched between the lambda function, and the docker image.
Locally I was building on an M1 with arm64
but the function is configured by default to use amd64
I changed my build command to
docker buildx build --platform linux/amd64 -t <image_name>:<image_tag>
Although I could have also updated the arch type for the lambda function to use arm64
Upvotes: 47