skip to Main Content

i have a python script in which i have included a handler like this [lambda_handler] (https://phpout.com/wp-content/uploads/2024/03/ZLcFG.png) and i have a dockerfileDockerFile used to build image which i am using to make a container image which is pushed to ECR and used to make a lambda function.

The problem is i am getting is

{
  "errorType": "Runtime.InvalidEntrypoint",
  "errorMessage": "RequestId: 86339395-a02e-4122-b54e-9f80a7bfbd40 Error: exec: "lambda_function.lambda_handler": executable file not found in $PATH"
}

i am just not sure what to put as the entry point. i have tried different solution like changing the architecture and build

as i am using a M2 MAC i thought the architecture might be the problem and changed the build

docker buildx build --platform linux/amd64 -t lambda-function .

and tried but still getting the invalid entry when tested in lambda

2

Answers


  1. As per AWS documentation you will need to move the "handler" file to Root Path. Which is defined with "${LAMBDA_TASK_ROOT}".

    Use the COPY command to copy the function code and runtime dependencies to {LAMBDA_TASK_ROOT}, a Lambda-defined environment variable.

    AWS Documentation: Python Deployment with Container Images

    Thus, the Dockerfile should look like:

    FROM public.ecr.aws/lambda/python:3.12
    
    # Copy requirements.txt
    COPY requirements.txt ${LAMBDA_TASK_ROOT}
    
    # Install the specified packages
    RUN pip install -r requirements.txt
    
    # Copy function code
    COPY lambda_function.py ${LAMBDA_TASK_ROOT}
    
    # Set the CMD to your handler (could also be done as a parameter override outside of the Dockerfile)
    CMD [ "lambda_function.handler" ]
    
    Login or Signup to reply.
  2. It seems like the error you’re encountering is related to the entry point specified for your Lambda function . Lambda expects the entry point to be a Python file and a function within that file , but it seems like it’s unable to find the executable file named lambda_function.lambda_handler .

    FROM python:3.12
    
    # Set working directory
    WORKDIR /app
    
    # Copy lambda function code
    COPY lambda_function.py .
    
    # Install dependencies if any
    # RUN pip install -r requirements.txt
    
    # Specify the command to run your script
    CMD ["lambda_function.lambda_handler"]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search