简体   繁体   English

无法导入AWS Lambda的请求

[英]Unable to import grequests for AWS Lambda

I'm running an AWS Lambda script with a Python 2.7 runtime. 我正在运行带有Python 2.7运行时的AWS Lambda脚本。 However, whenever it initializes it begins to import the grequests library but fails because of it's dependency on gevent: 但是,无论何时初始化它都会开始导入grequests库但由于它依赖于gevent而失败:

Gevent is required for grequests.

It seems it is successfully finding the grequests library (since it knows it needs gevent) but fails. 它似乎成功找到了grequests库(因为它知道它需要gevent)但是失败了。

What I've tried so far: 到目前为止我尝试过的:

pip install --ignore-installed grequests -t .

pip install --ignore-installed grequests -t ./lib

pip install --ignore-installed gevent -t .

pip install --ignore-installed gevent -t ./lib

And then I compress the contents of the directory and upload to AWS per the instructions here: http://docs.aws.amazon.com/lambda/latest/dg/lambda-python-how-to-create-deployment-package.html 然后我按照以下说明压缩目录的内容并上传到AWS: http//docs.aws.amazon.com/lambda/latest/dg/lambda-python-how-to-create-deployment-package。 HTML

It seems no matter what I try the Lambda is unable to locate gevent , but it's able to find other non-default libraries with no issue. 似乎无论我尝试什么Lambda无法找到gevent ,但它能够找到其他非默认库没有问题。

As Gevent is based on libev it is most likely compiling binaries when being installed via pip. 由于Gevent基于libev,因此很可能在通过pip安装时编译二进制文件。

You need to make sure that you are deploying binaries that are compiled for Amazon Linux if you want them to be executable in AWS Lambda. 如果您希望它们在AWS Lambda中可执行,则需要确保部署为Amazon Linux编译的二进制文件。 You can do so by building your deploy package on an EC2 instance that is running Amazon Linux. 您可以通过在运行Amazon Linux的EC2实例上构建部署包来实现此目的。

Also check out this answer and this tutorial . 另请参阅此答案本教程

I had to build gevent from src on an Amazon Linux instance. 我不得不在Amazon Linux实例上从src构建gevent I put the resultant files in a zip if anyone needs them--just include them in your uploaded Lambda zip and you should be concurrent-ing like a boss. 如果有人需要,我会将结果文件放在一个zip - 只需将它们包含在您上传的Lambda zip ,您应该像老板一样并发。

https://github.com/brandonmp/aws-lambda-grequests https://github.com/brandonmp/aws-lambda-grequests

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

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