简体   繁体   English

AWS Lambda 层

[英]AWS Lambda Layer

I am trying to import pandas library to my aws lambda layer.我正在尝试将 Pandas 库导入我的 aws lambda 层。 But is gives an error saying to cannot import lambda.function: no module names numpy.但是给出了一个错误,说不能导入 lambda.function: no module names numpy。

Can some explain what is the problem with pandas and aws.有人可以解释一下pandas和aws有什么问题吗? when I try to locally run it on pycharm using SAM it throws the same error.当我尝试使用 SAM 在 pycharm 上本地运行它时,它会引发相同的错误。

Lambdas have a limit of 125 MB as a part of the zip file or code that you upload and typically Pandas/Numpy are huge libraries that go past those limits potentially.作为您上传的 zip 文件或代码的一部分,Lambda 的限制为 125 MB,通常 Pandas/Numpy 是可能超过这些限制的巨大库。 Hence因此

1) If the part of your code that is using pandas can be replaced with other pythonic way of doing things (defaultdict, dict, lists etc) I recommend that 2) You can try zipping the dependancies (pandas or other libraries that you did a pip install with) in a linux environment, as Lambdas are in a linux environment. 1) 如果使用 Pandas 的代码部分可以用其他 Pythonic 的做事方式 (defaultdict、dict、lists 等) 替换,我建议 2) 您可以尝试压缩依赖项 (pandas 或其他库) pip install with) 在 linux 环境中,因为 Lambdas 在 linux 环境中。 You can follow this article: https://medium.com/i-like-big-data-and-i-cannot-lie/how-to-create-an-aws-lambda-python-3-6-deployment-package-using-docker-d0e847207dd6 3) You can maybe follow this: https://medium.com/@qtangs/creating-new-aws-lambda-layer-for-python-pandas-library-348b126e9f3e您可以关注这篇文章: https : //medium.com/i-like-big-data-and-i-cannot-lie/how-to-create-an-aws-lambda-python-3-6-deployment- package-using-docker-d0e847207dd6 3)你可以按照这个: https : //medium.com/@qtangs/creating-new-aws-lambda-layer-for-python-pandas-library-348b126e9f3e

If you are using AWS Lambda Layers you need to validate if your directory structure is on the needed structure for a layer:如果您使用AWS Lambda 层,则需要验证您的目录结构是否位于层所需的结构上:

For example for the pillow python module you need the following structure:例如,对于枕头python 模块,您需要以下结构:

aws-lambda-layer.zip
│ python
│ python/PIL
└ python/Pillow-5.3.0.dist-info

So to create a layer zip file with the correct structure we can use the following command on the root of our project:因此,要创建具有正确结构的层 zip 文件,我们可以在项目的根目录上使用以下命令:

mkdir -p python && cp -r <lib_name> python/ && zip -r aws-lambda-layer.zip python

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM