[英]Unable to import module 'lambda_function': No module named 'orjson.orjson'",
I'm trying to run a Python Lambda function (which ran successfully in 3.6, and I'm now trying to upgrade to a supported version).我正在尝试运行 Python Lambda function(在 3.6 中成功运行,我现在正在尝试升级到受支持的版本)。 I'm getting this result:
我得到这个结果:
Response
{
"errorMessage": "Unable to import module 'lambda_function': No module named 'orjson.orjson'",
"errorType": "Runtime.ImportModuleError",
"stackTrace": []
}
The orjson library is presumably a dependency of one of my dependencies, as I'm not importing it directly. orjson 库可能是我的依赖项之一的依赖项,因为我没有直接导入它。 I have tried to include all necessary dependencies as a layer, and I have experimented with a variety of ways to structure the zip file with the dependencies installed, but this issue persists.
我尝试将所有必要的依赖项包含为一个层,并且尝试了多种方法来构建安装了依赖项的 zip 文件,但这个问题仍然存在。
Is there anything I might be overlooking when creating the zip file for the layer?在为图层创建 zip 文件时,我可能会忽略什么吗?
I have been struggling with the same issue, and found out today that it is because orjson
is built on my Mac while AWS Lambda uses Amazon Linux, making the orjson
's cpython artifact incompatible when deployed.我一直在为同样的问题而苦苦挣扎,今天发现这是因为
orjson
是在我的 Mac 上构建的,而 AWS Lambda 使用 Amazon Linux,这使得orjson
的 cpython 工件在部署时不兼容。
Try using --use-container
option when running sam build
.运行
sam build
时尝试使用--use-container
选项。 This builds the artifact on an Amazon Linux container, and has resolved the issue for me.这会在 Amazon Linux 容器上构建工件,并为我解决了这个问题。
Hope this helps.希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.