AWS Lambda Bootstrap错误

时间:2018-07-06 14:16:48

标签: python-3.x amazon-web-services numpy aws-lambda

我正在尝试在AWS Lambda上运行微服务,因为它需要NumPy和pymysql依赖项,所以我遵循了here

所述的步骤

将依赖项和代码上传到S3并尝试运行测试功能时,我会收到此错误。

Traceback (most recent call last):
  File "/var/runtime/awslambda/bootstrap.py", line 538, in <module>
    main()
  File "/var/runtime/awslambda/bootstrap.py", line 528, in main
    run_init_handler(init_handler, invokeid)
  File "/var/runtime/awslambda/bootstrap.py", line 94, in run_init_handler
    init_handler()
TypeError: 'module' object is not callable

关于可能发生的事情的任何想法?它在我的EC2实例和本地计算机上均可正常运行

2 个答案:

答案 0 :(得分:0)

Lambda now has "layers" which could / should help you with that now.

But for others in the future, I had the exact same problem.

I had just finished refactoring a single-file Lambda Python module to a set of files, which included init.py. Turns out that if you have a module named init.py sitting next to a __init__.py in a package, some part of the AWS bootstrap processes can't handle the import or errors relating to the import; whether the file is good during import (your function times out) or bad (the traceback above).

I renamed init.py to connect.py (because I'm only setting up connection information for on-demand connections), then stopped seeing OP's traceback, and was able to move on.

I haven't attempted to reproduce with variations on init*.py module names.

Very strange edge case to run into.

答案 1 :(得分:0)

我也在无服务器应用程序中遇到了这个问题,事实证明,这取决于在case class E中定义处理程序的方式。引导程序将使用此值并尝试执行它。就我而言,它不是指向python文件中的函数,而是指向文件中的模块之一。

serverless.yaml

在somefile.py中,有一个jwt的导入。代码本来是要调用函数functions: some_lambda: handler: src/somefile.jwt 的,但是最终试图调用jwt模块,从而导致OP看到错误。