简体   繁体   English

如何使用无服务器将 librosa (python lib) 添加到 aws lambda

[英]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推荐/支持的是:

  • Compress the dependency压缩依赖
  • Add a Lambda Layer (eg 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.

相关问题 如何将 python 库添加到用于 Alexa 的 AWS lambda function? - How do I add python libraries to an AWS lambda function for Alexa? 使用无服务器框架将 Python package 部署到 AWS lambda 时出错 - Error deploying Python package to AWS lambda using Serverless framework 如何在 S3 上存储大型 Python 依赖项(适用于无服务器的 AWS Lambda) - How to Store Large Python Dependencies on S3 (for AWS Lambda with Serverless) 如何使用AWS Web API和Lambda验证无服务器Web请求? - How to authenticate serverless web request using AWS Web API and Lambda? AWS Lambda 和 Python 中的 Open CV 的无服务器问题 - Serverless issue with AWS Lambda and Open CV in Python 如何将 selenium 和 chromedriver 添加到 AWS Lambda function? - How do I add selenium & chromedriver to an AWS Lambda function? 如何使用Python和Zappa获得AWS Lambda剩余时间? - How do I get an AWS Lambda Remaining time using Python and Zappa? 如何使用 Python SysLogHandler 从 Aws lambda 将 Syslog 发送到远程主机? - How do I send Syslog using Python SysLogHandler from Aws lambda to remote host? 如何在 Python 中模拟 AWS lambda start_execution? - How do I mock an AWS lambda start_execution in Python? 如何从AWS API将变量传递给Python Lambda - How do I pass variables to Python Lambda from AWS API
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM