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 回答
0
已接受的回答

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"

已回答 1 年前
profile picture
专家
已审核 2 个月前
  • 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
专家
已回答 1 年前
0

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

已回答 1 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则