[英]AWS Lambda - Uploaded dependency doesn't load the dependency's dependency
I've looked around but have had a hard time finding someone with a similar problem.我环顾四周,但很难找到有类似问题的人。 Most of the articles I come across have a hard time deploying a package. My problem is that the package I uploaded has a hard time finding its resources.
我遇到的大多数文章都很难部署 package。我的问题是我上传的 package 很难找到它的资源。
For more context: I am using python3, I have used both RedHat 7 and Windows 10 to follow these instructions to create the layer I need, and I have successfully been able to follow them to create a layer and import it into my lambda_function.py file.有关更多上下文:我正在使用 python3,我使用了 RedHat 7 和 Windows 10 来按照这些说明创建我需要的层,并且我已经成功地能够按照它们创建层并将其导入我的 lambda_function.py文件。 The module I am trying to import is called qrcode .
我要导入的模块称为qrcode 。 When the virtual environment is activated, I installed it with
pip install qrcode[pil]
on Windows 10 and pip3 install qrcode[pil]
on my RedHat 7 ec2 instance.激活虚拟环境后,我使用
pip install qrcode[pil]
on Windows 10 和pip3 install qrcode[pil]
在我的 RedHat 7 ec2 实例上安装它。 I have also tried to include a separate layer for pil itself, to which it still didn't work.我还尝试为 pil 本身包含一个单独的层,但它仍然不起作用。
The error: The stacktrace is as follows -错误:堆栈跟踪如下 -
{
"errorMessage": "No module named 'Image'",
"errorType": "ModuleNotFoundError",
"stackTrace": [
" File \"/var/task/lambda_function.py\", line 30, in lambda_handler\n img = qrcode.make(data)\n",
" File \"/opt/python/qrcode/main.py\", line 13, in make\n return qr.make_image()\n",
" File \"/opt/python/qrcode/main.py\", line 296, in make_image\n from qrcode.image.pil import PilImage\n",
" File \"/opt/python/qrcode/image/pil.py\", line 7, in <module>\n import Image\n"
]
}
I got it to work, though I'm not 100% pleased with the answer.我让它工作了,尽管我对答案不是 100% 满意。
Long story short, qrcode
had an issue importing PIL.长话短说,
qrcode
在导入 PIL 时遇到问题。 I came across this answer that talked about how lambda is missing some components in how it was built.我遇到了这个答案,它谈到了 lambda 如何在构建过程中缺少一些组件。 So I installed my package (
pip install qrcode
) and imported it as a layer, then I used an arn specific for pil (talked about here ), and it worked like a charm.所以我安装了我的 package (
pip install qrcode
) 并将其导入为一个层,然后我使用了一个特定于 pil 的 arn (在这里讨论过),它的工作就像一个魅力。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.