2

我想使用 matplotlib 在 AWS Lambda 函数中创建图像文件。由于我的系统运行的 Linux 版本与 Lambda 使用的不同,因此我收到了从 matplotlib 网站下载轮子(.whl 文件)的指导。我下载了matplotlib-3.3.3-cp36-cp36m-manylinux1_x86_64.whl https://files.pythonhosted.org/packages/d2/43/2bd63467490036697e7be71444fafc7b236923d614d4521979a200c6b559/matcp66666.3.3-cp6666.3.3-cp666.3.3-cp6664.whlinuxman_x8-36

到我正在创建我的部署包的文件夹。

首先,我有很多轮文件,不清楚这是否正确。其次,它不起作用。

然后我用命令打包了轮子

wheel unpack *.whl

这产生了一个包含 matplotlib 包的目录。

我的主要功能是

import matplotlib.pyplot

def lambda_handler(event, context):
return

我下了命令

zip -r my-deployment-package.zip .
zip -g my-deployment-package.zip lambda_function.py

并将 zip 上传到 s3 存储桶。然后我使用“aws lambda update-function-code...”命令来更新 lambda 函数。当我部署和测试时,我收到错误:“无法导入模块'lambda_function':没有名为'matplotlib'的模块”

认为 matplotlib 模块不存在(也许我需要对 whl 文件做一些事情或把它放在不同的地方),我激活了我的虚拟环境并启动了 python 解释器。尝试导入 matplotlib,我得到“找不到模块”。尝试在 matplotlib 目录上使用 pip install,它抱怨没有 setup.py:

$ pip install --no-index --find-links=. matplotlib-3.3.3/
ERROR: Directory 'matplotlib-3.3.3/' is not installable. Neither 'setup.py' nor 'pyproject.toml' found.

如何让模块被识别?

4

2 回答 2

1

借助 Serverless 框架和 Docker,您可以在一分钟内构建一个层。在这篇文章中查看我的答案。

如果您赶时间,请随意获取我为您打包的这个 lambda 层。它与 Python 3.8 兼容。这是 gdrive 下载链接

于 2020-11-18T03:48:35.050 回答
0

无需构建自己的层;https://github.com/keithrozario/Klayers上提供了大量可用的内容- 您只需将它们包含在您的 Lambda 配置中。

于 2020-11-18T15:21:56.327 回答