2

I'm trying to deploy a custom machine learning library on Lambda using a Lambda docker image.

The image is looking approximately as follows:

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

CMD mkdir -p /workspace
WORKDIR /workspace

# Copy necessary files (e.g. setup.py and library/)
COPY ...

# Install library and requirements
RUN pip3 install . --target "${LAMBDA_TASK_ROOT}"

# Copy lambda scripts
COPY ... "${LAMBDA_TASK_ROOT}/"

# CMD [ my_script.my_handler ]

Thus, it installs a local python package including dependencies to LAMBDA_TASK_ROOT (/var/task). The CMD (handler) is overriden in AWS, e.g. preprocessing.lambda_handler.

The container works fine for handlers that DO NOT use the custom python library (on AWS and locally). However, trying to use the custom library on AWS, it fails with Runtime.ImportModuleError claiming that "errorMessage": "Unable to import module 'MY_HANDLER': No module named 'MY_LIBRARY'".

Everything works when running the container locally with the runtime interface emulator. The file-level permissions should be ok as well.

Is there anything wrong with this approach?

1 Answer 1

2

Answering my own question here: There was no problem with the Docker container itself. The problem was that Lambda references docker image versions via their SHA, not the tag, thus update to the tag did not update the container of the functions. To update the container image, you have to use something like

aws lambda update-function-code --function-name $MY_FN --image-uri $MY_URI
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.