Hi,
From the error message, it seems that the Lambda function is unable to find the Handler method which is in the server.py file. Lambda tries to look for the server.py file but it is unable to find it. You can read more about setting the Python Lambda Handler here in this documentation
Please check the Lambda function, check the folder structure and confirm that the Handler that has been configured has the correct path.
For example, let's say I have the following folder structure in my Lambda function named "PythonLambda":
PythonLambda (This is the top Level folder which will have the same name as the Lambda function)
-> lambda-api (This is a sub-folder)
-> server.py (the server.py file is under the folder lambda-api)
If my Lambda handler is server.lambda_handler
, I will be getting an identical error as your error:
START RequestId: 1d69b994-d660-4d64-ac74-83f6a659ae5c Version: $LATEST
[ERROR] Runtime.ImportModuleError: Unable to import module 'server': No module named 'server'
Traceback (most recent call last):END RequestId: 1d69b994-d660-4d64-ac74-83f6a659ae5c
REPORT RequestId: 1d69b994-d660-4d64-ac74-83f6a659ae5c Duration: 1.04 ms Billed Duration: 2 ms Memory Size: 128 MB Max Memory Used: 37 MB
- This is because Lambda tries to look for server.py in the top level folder but is unable to find it.
In order to be able to successfully call this Lambda, we must change the handler to lambda-api.server.lambda_handler
so that Lambda can find it under the folder.
START RequestId: 3c1b9e59-7ed0-41fe-8207-abc163067f56 Version: $LATEST
END RequestId: 3c1b9e59-7ed0-41fe-8207-abc163067f56
REPORT RequestId: 3c1b9e59-7ed0-41fe-8207-abc163067f56 Duration: 0.90 ms Billed Duration: 1 ms Memory Size: 128 MB Max Memory Used: 37 MB
Relevant content
- Accepted Answerasked 2 months ago
- AWS OFFICIALUpdated 8 months ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated a month ago
Thank you, I understand
However the issue seems to be with CDK deployment because the server.py is not included in the lambda package. In order to verify, I have downloaded the lambda code and checked for server.py, which was missing.
I was wondering if this could be a CDK issue
Thank you Ryan
I managed to resolve the problems
cdk bootstrap
andcdk deploy