Unable to import module 'main': No module named 'main'

0

I had a lambda function linked to API Gateway. All was working very fine. Then, I've updated a file who was in the zip file of the lambda function. I've rebuilded my zip file and upload it. And now I got the error: [ERROR] Runtime.ImportModuleError: Unable to import module 'main': No module named 'main' Traceback (most recent call last):

But I didn't change anything exept a code line inside a python which have no link with that error. I already checked the filename (main.py) and function name (lambda_handler) => main.lambda_handler, chmod, ... I have no clue. It's been hours that I can move on. I need help

3 Answers
0
Accepted Answer

In some cases the error is related to a bad configuration in the value of handler. The handler value in the lambda configuration must have the value of the file.method. If your file is called _main.py and your method is called handler then you should set the value of the lambda handler to the following value "_main.handler"

answered a year ago
profile picture
EXPERT
reviewed a month ago
  • Yes. That is exactly what I have. My file is called main.py and my function is called lambda_handler. In AWS, my function handler is main.lambda_handler

0

Did you zip it the same way as the procedure here?
https://repost.aws/knowledge-center/lambda-import-module-error-python

profile picture
EXPERT
answered a year ago
0

It's working now. I've rebuilt my project from scratch but I still don't know why it didn't worked earlier

answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions