简体   繁体   English

迁移到 AWS Lambda 上的 arm64 显示错误:无法导入模块 'encryptor-lambda'

[英]Migrate to arm64 on AWS Lambda show error: Unable to import module 'encryptor-lambda'

I have a lambda function runs on Python 3.7 with architecture x86_64 before.我有一个 lambda function 在 Python 3.7 上运行,之前架构为 x86_64。 Now I would like to migrate it to arm64 to use the Graviton processor and upgrade to Python 3.9 as well.现在我想将它迁移到 arm64 以使用 Graviton 处理器并升级到 Python 3.9。

While I success to create the Python 3.9 virtual environment layer with the dependencies that I need, which is aws-encryption-sdk , when I change the architecture of my lambda function to arm64 and runtime to Python 3.9, below error shows after I test my code: While I success to create the Python 3.9 virtual environment layer with the dependencies that I need, which is aws-encryption-sdk , when I change the architecture of my lambda function to arm64 and runtime to Python 3.9, below error shows after I test my代码:

Unable to import module 'encryptor-lambda': /opt/python/cryptography/hazmat/bindings/_rust.abi3.so: cannot open shared object file: No such file or directory",

I went and check my virtual env layer and pretty sure the file /opt/python/cryptography/hazmat/bindings/_rust.abi3.so is existed there.我去检查了我的虚拟环境层,并且很确定文件/opt/python/cryptography/hazmat/bindings/_rust.abi3.so存在于那里。

Then I try to keep my runtime at Python 3.9 and switch back the architecture to x86, it works.然后我尝试将我的运行时保持在 Python 3.9 并将架构切换回 x86,它可以工作。 Only if I try to change to arm64 it has that error above.只有当我尝试更改为 arm64 时,才会出现上述错误。

I look up online and can't seems to have a solution or as of why is that.我在网上查了一下,似乎没有解决方案,或者为什么会这样。 Is it not possible to migrate for the lambda functions that requires dependencies?需要依赖的 lambda 函数不能迁移吗? Or am I missing anything?还是我错过了什么?

Any help will be appreciated.任何帮助将不胜感激。 Thank you.谢谢你。

Libraries like aws-encryption-sdk-python sometimes contain code/dependencies that are not pure Python and need to be compiled.aws-encryption-sdk-python这样的库有时包含不是纯 Python 并且需要编译的代码/依赖项。 When code needs to be "compiled" it is usually compiled for a target architecture (like ARM or x86) to run properly.当需要“编译”代码时,通常会针对目标架构(如 ARM 或 x86)进行编译以正常运行。


You can not run code compiled for one architecture on different architecture.您不能在不同架构上运行为一种架构编译的代码。 So I suspect that is the reason for your error.所以我怀疑这是你错误的原因。


Looking at the error message I suspect it is the cryptography library causing this issue.查看错误消息,我怀疑是密码库导致了这个问题。

The library uses Rust.该库使用 Rust。 If you check your error, you will see that the shared library for the Rust binding is the causing your error ( _rust.abi3.so ).如果您检查错误,您将看到 Rust 绑定的共享库是导致错误的原因 ( _rust.abi3.so )。 According to the documentation of the library, the ARM architecture is supported.根据库的文档,支持 ARM 架构。

Therefore, I suspect that the way you are packaging your Lambda deployment package and it's dependencies is the issue.因此,我怀疑您打包 Lambda 部署 package 的方式及其依赖关系是问题所在。 You are probably doing that on a computer with x86 architecture.您可能正在使用 x86 架构的计算机上执行此操作。 Package manager like pip usually detect the OS and architecture they are run on and download dependencies for those OS's and architectures. Package 管理器(如pip通常检测它们运行的操作系统和架构,并下载这些操作系统和架构的依赖项。

So I guess you have two options:所以我想你有两个选择:

  1. Run your build/deployment on an ARM machine在 ARM 机器上运行您的构建/部署
  2. Somehow manage to "cross compile" with tools like crossenv不知何故设法使用crossenv之类的工具“交叉编译”

Both options are not really great.这两种选择都不是很好。

Unfortunately, this is one of those areas where Python Lambdas can become very cumbersome to develop/deploy.不幸的是,这是 Python Lambda 开发/部署可能变得非常麻烦的领域之一。 Every time a depdency uses a non-Python extension (like a C extension), packaging/deployment becomes a problem.每次依赖使用非 Python 扩展(如 C 扩展)时,打包/部署都会成为问题。

Maybe someone else has a great tool to recommend.也许其他人有一个很棒的工具可以推荐。

The answer that Jens gave is correct. Jens 给出的答案是正确的。 But more concisely, you built your environment on x86_64 and downloaded the x86_64 wheel for cryptography.但更简洁地说,您在 x86_64 上构建了您的环境并下载了 x86_64 轮子进行密码学。 You will need to build the environment on Arm to deploy on Arm.您需要在 Arm 上构建环境以部署在 Arm 上。

Another option you could consider is using Docker buildx to build for both platforms under emulation with qemu, as long as the build doesn't take long.您可以考虑的另一个选择是使用 Docker buildx 为使用 qemu 仿真的两个平台构建,只要构建不需要很长时间。 Emulation slows things down significantly.仿真大大减慢了速度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AWS Lambda 错误消息“无法导入模块'lambda_function':没有名为'lambda_function'的模块”, - AWS Lambda error message “Unable to import module 'lambda_function': No module named 'lambda_function'”, 如何修复 AWS lambda 中的“无法导入模块”错误 - How to fix "Unable to import module" error in AWS lambda 带有压缩依赖项的 AWS Lambda“无法导入模块” - AWS Lambda “Unable to import module” with Zipped Dependencies Python:无法在AWS Lambda中导入模块应用程序 - Python: Unable to import module app in AWS Lambda 在AWS Lambda中收到错误“无法导入模块'lambda_function':没有名为Flask的模块”的错误 - Getting the error “Unable to import module 'lambda_function': No module named Flask” in AWS Lambda AWS Lambda 无法从层导入模块 - AWS Lambda unable to import module from layer 无法在AWS Lambda(Python)中导入模块 - Unable to import module in AWS Lambda (Python) AWS Lambda - 无法导入模块“lambda_function” - AWS Lambda - unable to import module 'lambda_function' AWS Lambda 错误:无法导入模块“function_name”:没有名为“module._module”的模块 - AWS Lambda Error: Unable to import module 'function_name': No module named 'module._module' AWS Lambda 函数抛出“导入模块错误” - AWS Lambda function throws “Import module error”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM