我有一个使用Google Cloud Pubsub的Python应用程序,如下所示:
from google.cloud import pubsub它在本地运行得很好,但在调用AWS Lambda函数时,我得到了:
Unable to import module 'handler': cannot import name 'pubsub'并且没有其他错误或详细信息。
我的requirements.txt文件:
requests
google-cloud-datastore==1.4.0
google-cloud-pubsub==0.29.0
sqlalchemy我有一种感觉,这可能是对pubsub的psutil要求,因为当我尝试在pubsub之前导入psutil时,我得到了这个错误:
Unable to import module 'handler': cannot import name '_psutil_linux'发布于 2017-11-19 10:47:13
如果您使用的是serverless库,解决方案是执行以下操作:
删除项目目录中的.requirements文件夹
将以下内容添加到您的serverless.yml文件(docs here):
custom:
pythonRequirements:
dockerizePip: true发布于 2017-11-19 10:16:38
您需要将lambda函数预打包到包含外部模块的zip文件中。
pip install module-name -t /path/to/project-dir
然后使用包含的模块压缩您的代码,并上传zip文件。
参考:http://docs.aws.amazon.com/lambda/latest/dg/lambda-python-how-to-create-deployment-package.html
https://stackoverflow.com/questions/47373043
复制相似问题