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 Risposte
0
Risposta accettata

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"

con risposta un anno fa
profile picture
ESPERTO
verificato 2 mesi fa
  • 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
ESPERTO
con risposta un anno fa
0

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

con risposta un anno fa

Accesso non effettuato. Accedi per postare una risposta.

Una buona risposta soddisfa chiaramente la domanda, fornisce un feedback costruttivo e incoraggia la crescita professionale del richiedente.

Linee guida per rispondere alle domande