Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to import grequests for AWS Lambda

I'm running an AWS Lambda script with a Python 2.7 runtime. However, whenever it initializes it begins to import the grequests library but fails because of it's dependency on gevent:

Gevent is required for grequests.

It seems it is successfully finding the grequests library (since it knows it needs gevent) but fails.

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

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.

like image 432
Tyler Mills Avatar asked Mar 27 '16 06:03

Tyler Mills


2 Answers

I had to build gevent from src on an Amazon Linux instance. 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.

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

like image 125
Brandon Avatar answered Nov 12 '22 17:11

Brandon


As Gevent is based on libev it is most likely compiling binaries when being installed via 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. You can do so by building your deploy package on an EC2 instance that is running Amazon Linux.

Also check out this answer and this tutorial.

like image 28
birnbaum Avatar answered Nov 12 '22 16:11

birnbaum