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 Antworten
0
Akzeptierte Antwort

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"

beantwortet vor einem Jahr
profile picture
EXPERTE
überprüft vor 2 Monaten
  • 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
EXPERTE
beantwortet vor einem Jahr
0

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

beantwortet vor einem Jahr

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen