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
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