aws / aws-lambda-base-images

Apache License 2.0
669 stars 110 forks source link

Python 3.10 Lambda throws an error in the AWS Console but works using Lambda Docker Image #97

Open leslie-alldridge opened 1 year ago

leslie-alldridge commented 1 year ago

Background: We updated all of our Lambda to Python 3.10 and noticed a couple throwing this error

[ERROR] Runtime.ImportModuleError: Unable to import module 'handler': libc.musl-x86_64.so.1: 
cannot open shared object file: No such file or directoryTraceback (most recent call last): 
| [ERROR] Runtime.ImportModuleError: 
Unable to import module 'handler': libc.musl-x86_64.so.1: cannot open shared object file: No such file or directory 
Traceback (most recent call last):
-- | --

Googling online it looks like a fix is to deploy the lambda code in a docker container and install the missing depdendencies. Before going down that path I figured it would be worth testing our builds locally using the AWS Provided lambda images.

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

....

COPY ./src/blah/handler.py ${LAMBDA_TASK_ROOT}
COPY ./src/blah/requirements.txt ${LAMBDA_TASK_ROOT}

RUN pip install -r ${LAMBDA_TASK_ROOT}/requirements.txt

CMD [ "handler.main" ]

When running the code locally in docker and sending it a request, the response comes back perfectly without any errors.

It seems like there's disparity between the docker image and what's used in the AWS Console. Is someone able to confirm or update the Python 3.10 used in the AWS Console?

DilLip-Chowdary-Codes commented 1 year ago

can you provide your code (at least the core part causing the issue), most probably this could be caused by a third-party package that requires the mentioned library

and lambda removed a few inbuild libraries/binaries which are in previous runtimes, we need to add them in layers if this is the case.

anyway, this should be reproduced with both console level and custom image.