[英]AWS Python Lambda Unable to Import Module In zip File constructed on CodeBuild
I am trying to deploy a python lambda function with a zip file archive .我正在尝试部署python lambda function 和 zip 文件存档。
Using AWS CodeBuild I followed the instructions to setup a zip file with my source code and dependencies at the top level .使用 AWS CodeBuild,我按照说明在顶层设置了一个包含我的源代码和依赖项的 zip 文件。
However, when I invoke my Lambda function an import error is reported:但是,当我调用我的 Lambda function 时,报导入错误:
{
"errorMessage": "Unable to import module 'my_module': No module named 'cytoolz.itertoolz'",
"errorType": "Runtime.ImportModuleError",
"requestId": "<random uuid>",
"stackTrace": []
}
Why is Lambda unable to find a dependency that exists within a zip file that is built using CodeBuild?为什么 Lambda 无法找到存在于使用 CodeBuild 构建的 zip 文件中的依赖项?
The problem is with python versions.问题出在 python 版本上。 The Standard 6.0
CodeBuild environment has python 3.10
installed but the python runtime environment in Lambda only goes up to 3.9
(at the time of this answer). Standard 6.0
CodeBuild 环境已安装 python 3.10
,但 Lambda 中的 python 运行时环境仅升至3.9
(在回答此问题时)。
Therefore, when installing the dependencies into the zip file因此,在将依赖项安装到 zip 文件中时
pip install --target ./package requests
cd package
zip -r ../my-deployment-package.zip .
The version of pip is 3.10 and all of the dependencies that are installed and packaged in the zip file are the wrong python version. pip的版本是3.10,zip文件中安装打包的依赖都是错误的python版本。
In CodeBuild install a python & pip 3.9 to create the zip file.在 CodeBuild 中安装 python & pip 3.9 以创建 zip 文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.