【发布时间】:2021-03-28 05:18:45
【问题描述】:
我在将 argon2-cffi python module (version 20.1.0) 从 AWS Lambda 层导入 AWS Lambda 函数时遇到问题。
这似乎适用于所有以 C 为基础的包,因为我用 pandas 测试了它并得到了相同的结果。
我对 Layer 的 cloudformation 配置如下:
MyLib:
Type: AWS::Serverless::LayerVersion
Properties:
LayerName: my-lib
Description: In-house and 3rd party dependencies for my app.
ContentUri: lambdas/lib/.
CompatibleRuntimes:
- python3.8
/lib里面的文件夹结构是这样的:
lib
├── python
│ ├── app
│ │ └── ...
│ └── lib/python3.8/site-packages
│ ├── argon2
│ │ └── ...
│ ├── argon2_cffi-20.1.0.dist-info
│ │ └── ...
│ ├── ...
│ └── stdnum
│ └── ...
└── requirements.txt
根据recommendations from AWS,python/app 文件夹包含我的自定义库,python/lib/python3.8/site-packages 文件夹包含第 3 方包。
我知道由于 argon2 依赖于 C 代码 it must be installed on the runtime environment that the Lambda function using it will be hosted in,所以我使用 AWS 提供的 docker 镜像通过命令将包安装到 lib/python3.8/site-packages 中
docker run -v "$PWD":/var/task "lambci/lambda:build-python3.8" /bin/sh -c "pip install -r requirements.txt -t python/lib/python3.8/site-packages/; exit"
我尝试运行的 lambda 函数在 cloudformation 模板中配置为
AuthorizerFunction:
Type: 'AWS::Serverless::Function'
Properties:
CodeUri: lambdas/handlers
Handler: authorizer.handler
Runtime: python3.8
...
Layers:
- !Ref MyLib
并从这些导入开始:
# authorizer.py
import app.utils as utils
import stdnum
from argon2 import PasswordHasher
但是当我尝试运行它时,我收到以下错误
[ERROR] Runtime.ImportModuleError: Unable to import module 'authorizer': No module named 'argon2._ffi'
表示app和stdnum都导入成功,但argon2没有。
有什么想法可能是错的吗?
我也欢迎任何关于另一个具有久经考验的散列算法的散列库的建议。
更新:按照推荐的here 更新我的cffi、pip 和setuptools 并没有成功。
更新 2:我可以看到使用 docker 命令安装的氩气是 linux 兼容的,因为输出包括以下几行:
Collecting argon2-cffi==20.1.0
Downloading argon2_cffi-20.1.0-cp35-abi3-manylinux1_x86_64.whl (97 kB)
【问题讨论】:
标签: python amazon-web-services aws-lambda aws-lambda-layers