[英]How do I add librosa (python lib) to aws lambda using serverless
I'm trying to use https://www.serverless.com/ to manage dependencies for a simple aws lambda function.我正在尝试使用https://www.serverless.com/来管理简单 aws lambda function 的依赖项。
A key dependency is the librosa python library ( https://github.com/librosa/librosa ).一个关键依赖项是 librosa python 库( https://github.com/librosa/librosa )。
I am new to serverless
, so I'd appreciate guidance with the serverless.yml
file.我是serverless
的新手,所以我很感谢serverless.yml
文件的指导。
So far I have到目前为止我有
service: my-app-123
app: my-app-123-app
org: my-org
frameworkVersion: '2'
provider:
name: aws
runtime: python3.6
stage: dev
region: eu-west-2
plugins:
- serverless-python-requirements
functions:
hello:
handler: handler.hello
package:
individually: false
exclude:
- '**/*'
include:
- handler.py
and requirements.txt
is:和requirements.txt
是:
librosa==0.8.0
pandas==1.1.5
When I tried the above I got this error:当我尝试上述方法时,出现此错误:
An error occurred: HelloLambdaFunction - Unzipped size must be smaller than 262144000 bytes (Service: AWSLambdaInternal; Status Code: 400; Error Code: InvalidParameterValueException; Request ID: f6bd001e-5592-44c8-8f10-3b56180d7ec7; Proxy: null).
You're hitting the size limitations of your AWS Lambda deployment package, see here .您正在达到 AWS Lambda 部署 package 的大小限制,请参见此处。 It can be maximal 250 MB unzipped (that's what your error message tells you).解压缩后最多可以有 250 MB(这就是您的错误消息告诉您的内容)。
Have a look at the section Dealing with Lambda's size limitations in the documentation of the serverless-python-requirements plugin.查看serverless-python-requirements插件文档中的处理 Lambda 的大小限制部分。
In short what serverless-python-requirements
recommends/supports is:简而言之, serverless-python-requirements
推荐/支持的是:
librosa
alone)添加Lambda 层(例如单独的librosa
) Compression works by adding the following in your serverless.yml
通过在serverless.yml
中添加以下内容来进行压缩
custom:
pythonRequirements:
zip: true
and then add this to your handler before using your dependencies:然后在使用您的依赖项之前将其添加到您的处理程序:
try:
import unzip_requirements
except ImportError:
pass
But some users seem to have had issues with librosa
and couldn't seem to make it work, see this GitHub issue for example or this other SO question .但是有些用户似乎对librosa
有疑问,并且似乎无法使其正常工作,例如参见此 GitHub 问题或此其他 SO 问题。
A suggestion in there was to split up your Lambdas and chain them, ie one Lambda which has only librosa
as a dependency (maybe with compression of the dependency) and then handing off for further processing to a second Lambda, I don't know what you're trying to do if this is feasible for you.那里的一个建议是拆分你的 Lambda 并将它们链接起来,即一个 Lambda,它只有librosa
作为依赖项(可能会压缩依赖项),然后移交给第二个 Lambda 进行进一步处理,我不知道是什么如果这对您可行,您正在尝试做。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.