Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

basic config to run a python docker image via AWS Lambda function

I have five hours trying to get a Lambda function to successfully return a response, using a Docker image, and failing miserably.

Dockerfile

FROM python:3.9.6-buster
WORKDIR /app
COPY . /app
CMD ["python", "/app/lambda_handler.py"]

Python files
p.py

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

def c(a1, a1, a1):
    result = {
        "a1": a1,
        "a2": a2,
        "a3": a3,
    }
    return result

lambda_handler.py

import json
from p import c
def lambda_handler(event, context):
    arg1 = event["a1"]
    arg2 = event["a2"]
    arg3 = event["a3"]

    result = classify(arg1, arg2, arg3)

    response = {"statusCode": 200, "body": result}

    return json.dumps(response, indent=4, default=str)

I get an unhelpful error of

{
"errorType": "Runtime.InvalidEntrypoint",
"errorMessage": "RequestId: 330fa2c3-f68b-4225-a53c-96f2409f186d Error: exec: "lambda_function.lambda_handler": executable file not found in $PATH"
}

I have tried:

  • zipping the files and uploading to the lambda function which works
  • read this link which suggests using using something like CMD [ "lambda_function.handler" ] so I have set the override CMD to combinations of app.lambda_function.lambda_handler, lambda_function.lambda_handler with and without quotes
  • I have tried setting the ENTRYPOINT to python, and then trying to point the CMD to /app/lambda_handler
  • instead of using CMD exclusively using ENTRYPOINT override python, /app/lambda_handler.py

Any help would be most appreciated.

>Solution :

The error appears to be a configuration problem with your AWS Lambda function.

If you check the message it says Error type: Runtime.InvalidEntrypoint ... Error: exec: "lambda_function.lambda_handler"

By default the Entrypoint of AWS Lambda in the console is lambda_function.lambda_handler and according to the documentation this is

.. This function handler name reflects the function name (lambda_handler) and the file where the handler code is stored (lambda_function.py).

In your case your python file is named lambda_handler.py instead of lambda_function.py which is why AWS Lambda fails to find your handler and throws the error InvalidEntrypoint.

Try changing the name of your file to lambda_function.py

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading