过去几天我一直在处理这个问题。我正在尝试使用以下模块创建一个 lambda 层:密码学、ldap3 和 bonsai,以在我的 lambda_function 中使用,该函数的运行时为 python3.11,架构类型为 x86_64。我一直在使用 AWS CloudShell 创建 lambda_layer zip 文件。
这就是我安装密码学和 ldap3 的方式:
-pip3.11 install \
--platform manylinux2014_x86_64 \
--target=my-lambda-function \
--implementation cp \
--python-version 3.11.8 \
--only-binary=:all: --upgrade \
cryptography
-pip3.11 install \
--platform manylinux2014_x86_64 \
--target=my-lambda-function \
--implementation cp \
--python-version 3.11.8 \
--only-binary=:all: --upgrade \
ldap3
这两个模块工作得很好,我可以在 lambda 函数中调用该模块,问题出在 bonsai 模块上。 不幸的是,我无法像这样安装盆景模块:
pip3.11 install \
--platform manylinux2014_x86_64 \
--target=my-lambda-function \
--implementation cp \
--python-version 3.11.8 \
--only-binary=:all: --upgrade \
bonsai
因为当我运行此命令时出现以下错误:
ERROR: Could not find a version that satisfies the requirement bonsai (from versions:none)
ERROR: No matching distribution found for bonsai
因此这就是我安装盆景的方式:
pip3.11 install bonsai --target=my-lambda-function
但是当我尝试在 lambda 函数中调用 bonsai 模块时,出现此错误:
Unable to import module 'lambda function': libldap_r-2.4.so.2 cannot open shared objectfile: No such file or directory
有谁知道如何解决这个问题,我完全碰壁了。欢迎任何帮助!
您可以尝试从存储库安装;
pip install https://github.com/BonsaiAI/bonsai-python
您可以在 CodeBuild 中构建并将工件推送到 s3。 本文讨论使用 CloudFormation 创建带有 s3 工件引用的层; https://www.linkedin.com/pulse/lambda-layer-creation-cloudformation-martin-macecek/
您可以尝试在 docker 镜像内构建与 lambda 目标操作系统相同的操作系统。
该 .so 文件不可用于 lambda 操作系统。我认为这是需要以某种方式解决的问题。