Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Lambda error message "Unable to import module 'lambda_function': No module named 'lambda_function'",

I am trying to upload a zip file to AWS lambda but keep getting the error "Unable to import module 'lambda_function': No module named 'lambda_function'"

I've started very basic by creating a zip file named "lambda_function.zip" with one file inside "lambda_function.py". At a later stage I will need to include packages in the zip file, but for now it's a very simple function named lambda_handler only using json.

Once uploaded this is the file structure and the error message received after testing: code and error message screenshot

If I move lamda_function.py into the root folder "RWS-POC" then it works, but later on when I need to upload a larger zip file this won't be an option as editing via the interface is disabled.

I can also confirm that the handler is set to lambda_function.lambda_handler and the python file is named "lambda_function" and the function named "lambda_handler" lambda_function.lambda_handler settings screenshot

I'm sure I'm doing something very basic wrong, so any help would be very much appreciated.

Thanks!

like image 647
Dais.S Avatar asked Feb 21 '26 17:02

Dais.S


1 Answers

Your lambda_function.py is inside folder called lambda_function. Just move your lambda_function to RWS-POC, or modify handler into:

lambda_function/lambda_function.lambda_handler
like image 162
Marcin Avatar answered Feb 24 '26 07:02

Marcin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!