将argon2-cffi
{a1}从AWS Lambda层导入AWS Lambda函数时遇到问题
这似乎适用于所有以C为基础的包,因为我用pandas
测试了它,得到了相同的结果
我对该层的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
文件夹包含第三方软件包
我知道,由于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
你知道哪里不对吗
我也欢迎任何关于另一个哈希库的建议,该库使用了经过测试的哈希算法
更新:按照建议更新我的cffi
、pip
和setuptools
并没有起到作用
更新2:我可以看到使用docker命令安装的argon是linux兼容的,因为输出包括以下几行:
Collecting argon2-cffi==20.1.0
Downloading argon2_cffi-20.1.0-cp35-abi3-manylinux1_x86_64.whl (97 kB)
好吧,我的问题的答案有点尴尬。不管怎样,我都会把它贴在这里,以防它可能会破坏别人的理解
我使用git进行源代码控制,并使用VS代码中的模板来处理
.gitignore
文件。此外,我还设置了一个自动构建和部署过程,该过程基于git repo中的内容构建Lambda应用程序经过几天的调试,我发现Lambda层的
argon2_cffi
文件夹中缺少了.so
文件。罪魁祸首是前面提到的.gitignore
文件,其中包含以下行:难怪基于C的python包都不能工作
我从
.gitignore
中删除了上述行,并将所有.so
文件提交到repo,而之前从未提交到Lambda层,现在一切正常相关问题 更多 >
编程相关推荐