简体   繁体   English

部署到AWS Lambda匹配大小限制和包(例如numpy)不兼容

[英]Deploying to AWS lambda hits size limit and packages (such as numpy) are not compatible

I have a relatively small script where I use the following dependencies: 我有一个相对较小的脚本,在其中使用以下依赖项:

firebase-admin
pandas

Nevertheless, when you install these dependencies you get over 60 additional dependencies installed as well, such as numpy , scikit , google_cloud etc. 不过,当您安装这些依赖项时,还会安装60多个其他依赖项,例如numpyscikitgoogle_cloud等。

I encountered many problems during deployment, of which the following were the most striking: 在部署过程中,我遇到了许多问题,其中最引人注目的是:

  1. You quickly hit the size limit of 250MB. 您很快就达到了250MB的大小限制。 numpy alone is approx 100mb. 仅numpy约为100mb。
  2. Some packages with compiled libraries are not compatible, eg numpy , so you need to unwheel them (see link ). 某些带有编译库的软件包不兼容,例如numpy ,因此您需要展开它们(请参阅link )。

I have spent now maybe two days trying to get around these problems. 我现在可能已经花了两天时间来解决这些问题。 However, I did not manage to succeed to run my small script at all. 但是,我根本没有成功运行小脚本。

I am therefore wondering: 因此,我想知道:

  • Is AWS lambda at all suitable for my use case given the difficulties in deploying? 部署困难,AWS Lambda完全适合我的用例吗? If it is so hard to deploy a simple script with the dependencies listed above? 如果使用上面列出的依赖项部署一个简单的脚本是否如此困难?
  • What are other good practices to overcome the dependency installation? 还有哪些其他好的方法可以克服依赖项安装问题? Is it possible to split up the dependencies from the actual functions? 是否可以将依赖项与实际功能分开?
  • What are other better (more simple) ways to deploy to Lambda? 还有什么更好(更简单)的方法可以部署到Lambda? In particular, I find it cumbersome to zip every time all my functions and site-packages in order to just to do a small update . 特别是,我发现每次我所有的功能和站点软件包都压缩以仅进行一个小的更新就很麻烦。

Note on the latter: I have tried also the following solutions: 关于后者的说明:我也尝试了以下解决方案:

  • zappa : Following this tutorial , I tried deploying it using zappa. zappa :在本教程之后 ,我尝试使用zappa进行部署。 After encountering and somehow resolving the size limit problem, I had another problem which is that my small script did not had an app function in the format myservice.app. 遇到并以某种方式解决了大小限制问题后,我遇到了另一个问题,这是我的小脚本没有myservice.app格式的应用程序功能。 After googling I found that zappa was designed for WSGI apps. 谷歌搜索之后,我发现zappa是为WSGI应用程序设计的。
  • python-lambda : I also tried this other often recommended alternative. python-lambda :我也尝试了其他经常推荐的替代方法。 However, I was unable to call the command lambda init after installation. 但是,安装后我无法调用命令lambda init See my question on that issue here . 这里看到我关于这个问题的问题。
  • using aws sam and layers . 使用aws sam和layers I followed the README.me after installing aws-sam-cli and followed all the steps. 安装aws-sam-cli之后,我遵循了README.me并遵循了所有步骤。 This resulted that I uploaded a new package on S3, which I used to create a new layer. 结果,我在S3上上传了一个新软件包,用于创建新图层。 Nevertheless, I kept receiving the error "numpy not found" despite that I put numpy in my requirements.txt and properly build the site packages (as it was in my SamApp visible). 尽管如此,尽管我将numpy放入我的requirements.txt中并正确构建了站点包(因为它在我的SamApp中可见),但我仍然收到错误“找不到numpy”。

You can deploy to lambda & surrounding services using serverless framework. 您可以使用无服务器框架部署到lambda和周围的服务。 I use serverless framework with the serverless-python-requirements plugin which will compile and bundle any needed python requirements. 我将无服务器框架与无服务器python需求插件一起使用,该插件将编译并捆绑任何所需的python要求。 Under the hood it translates into a cloudformation template and deploys your function(s) and dependent resources as a stack into AWS. 它在后台转换为cloudformation模板,并将您的功能和相关资源作为堆栈部署到AWS中。

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

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