简体   繁体   English

AWS Python Lambda 无法在 zip 上构建的文件中导入模块 CodeBuild

[英]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.

相关问题 AWS Lambda - 无法导入模块“lambda_function” - AWS Lambda - unable to import module 'lambda_function' AWS Lambda Opencv(“无法导入模块‘lambda_function’:libgthread-2.0.so.0:无法打开共享对象文件:没有这样的文件或目录”) - AWS Lambda Opencv ("Unable to import module 'lambda_function': libgthread-2.0.so.0: cannot open shared object file: No such file or directory") AWS Lambda 层无法导入模块“lambda_function”:没有名为“pyarrow.lib”的模块 - AWS Lambda Layer Unable to import module 'lambda_function': No module named 'pyarrow.lib' aws lambda 无法导入模块“lambda_function”:没有名为“requests”的模块 - aws lambda Unable to import module 'lambda_function': No module named 'requests' AWS Lambda 导入错误:无法导入模块“lambda_function”:没有名为“confluent_kafka.cimpl”的模块 - AWS Lambda importError: Unable to import module 'lambda_function': No module named 'confluent_kafka.cimpl 无法导入模块“lambda_function”:没有名为“psycopg2._psycopg aws lambda 函数”的模块 - Unable to import module 'lambda_function': No module named 'psycopg2._psycopg aws lambda function AWS Lambda 导入 psycopg2 - 无法导入模块“app”:没有名为“psycopg2._psycopg”的模块 - AWS Lambda Importing psycopg2 - Unable to import module 'app': No module named 'psycopg2._psycopg 无法导入模块“app”:使用 Chalice 在 Aws Lambda 中没有名为“app”的模块 - Unable to import module 'app': No module named 'app' in Aws Lambda using Chalice 无法导入模块“lambda_function”:没有名为“aws_xray_sdk”的模块 - Unable to import module 'lambda_function': No module named 'aws_xray_sdk' 无法在 AWS Lambda 中导入 numpy 1.19.1 没有名为“numpy.core._multiarray_umath”的模块 - Unable to import numpy 1.19.1 in AWS Lambda No module named 'numpy.core._multiarray_umath'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM