AWS Lambda: Runtime.InvalidEntrypoint

0

I've been beating my head off a wall all day while trying to deploy a docker image to a lambda function.

I have this docker image:

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

# Set working directory to Lambda task root
WORKDIR \${LAMBDA_TASK_ROOT}

# Copy the requirements.txt first, for separate dependency resolving
COPY requirements.txt \${LAMBDA_TASK_ROOT}

# Install any dependencies
RUN pip install -r requirements.txt

# Copy the rest of your lambda function code
COPY . \${LAMBDA_TASK_ROOT}

# Set the CMD to your handler
CMD ["lambda_function.handler"]

and a "lambda_function.py" with a handler function within it. Can anyone see see the issue?

Megil
asked 4 months ago326 views
2 Answers
0

Hello.

Looking at the stackoverflow answers below there may be a possible architecture compatibility issue.
Therefore, try changing the architecture on the Lambda side or specifying the architecture when running "docker build".
Also, check if any other error logs are output.
I think there are other messages output in addition to the "Runtime.InvalidEntrypoint" message.
https://stackoverflow.com/questions/71373337/invalidentrypoint-for-aws-lambda-with-python-docker-container

profile picture
EXPERT
answered 4 months ago
0

Hi,

Your code doesn't have ENTRYPOINT specified. I believe that is an issue.

Look at example from https://docs.aws.amazon.com/lambda/latest/dg/python-image.html#python-image-instructions:

# Define custom function directory
ARG FUNCTION_DIR="/function"

FROM python:3.12 as build-image

# Include global arg in this stage of the build
ARG FUNCTION_DIR

# Copy function code
RUN mkdir -p ${FUNCTION_DIR}
COPY . ${FUNCTION_DIR}

# Install the function's dependencies
RUN pip install \
    --target ${FUNCTION_DIR} \
        awslambdaric

# Use a slim version of the base Python image to reduce the final image size
FROM python:3.12-slim

# Include global arg in this stage of the build
ARG FUNCTION_DIR
# Set working directory to function root directory
WORKDIR ${FUNCTION_DIR}

# Copy in the built dependencies
COPY --from=build-image ${FUNCTION_DIR} ${FUNCTION_DIR}

# Set runtime interface client as default command for the container runtime
ENTRYPOINT [ "/usr/local/bin/python", "-m", "awslambdaric" ]
# Pass the name of the function handler as an argument to the runtime
CMD [ "lambda_function.handler" ]

I believe that you should start from this example, get in to work and then adapt to your use case.

The practice of using a Dockerfile using 2 images in cascade is important to have a smaller image at the end: it reduces costs and improves perfs.

Best,

Didier

profile pictureAWS
EXPERT
answered 4 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions