Using Shapely on AWS Lambda with Python 3

0 votes

I am trying to set up a skill using Shapely on Lambda. I got the error

module initialization error: Could not find lib geos_c or load any of its variants ['libgeos_c.so.1', 'libgeos_c.so'].

There's a similar question for Python 2.7. I can't use the lambda-packs by ryfeus cause I'm on Python 3.6, but I figured the EC2 approach described by Graeme should work.

So I started up an EC2 instance using the Public Amazon Linux AMI version from the AWS docs

I then ran these commands

$ sudo yum -y update
$ sudo yum -y install python36 python36-virtualenv python36-pip
$ mkdir ~/forlambda
$ cd ~/forlambda
$ virtualenv -p python3 venv
$ source venv/bin/activate

and then installed Shapely and a few other packages I needed.

$ sudo yum -y groupinstall "Development Tools"
$ pip install python-dateutil
$ pip install shapely 
$ pip install pyproj 
$ pip install pyshp

I then ran my skill (on the EC2 instance), and it works! So then I copied the files at venv/lib/python3.6/site-packages, plus the myskill.py and zipped them up, uploaded to Lambda, and still get the geos_c error as shown above :(

I have been able to upload a scaled-down version of my skill (minus Shapely, but including other packages that don't come with Lambda) and it works on Lambda, so I don't think it's an error on how I am zipping or uploading.

Am I missing something? Does it make a difference that the Development Tools were installed using "sudo yum install" instead of "pip install"?

Oct 8, 2018 in AWS by eatcodesleeprepeat
• 4,710 points
2,969 views

1 answer to this question.

0 votes

For some reason, the pip install of Shapely and Pyproj didn't end up in the virtualenv site-packages. From a fresh EC2 instance, I ran these commands:

$ sudo yum -y update
$ sudo yum -y install python36 python36-virtualenv python36-pip
$ mkdir ~/forlambda
$ cd ~/forlambda
$ virtualenv -p python3 venv
$ source venv/bin/activate

(venv) $ sudo yum -y groupinstall "Development Tools"
(venv) $ pip install python-dateutil
(venv) $ pip install shapely -t ~/forlambda/venv/lib/python3.6/site-packages/
(venv) $ pip install pyproj -t ~/forlambda/venv/lib/python3.6/site-packages/
(venv) $ pip install pyshp

and then zipped up all the contents of site-packages/ plus myskill.py, uploaded to Lambda, and it worked.

answered Oct 8, 2018 by Priyaj
• 58,020 points

Related Questions In AWS

0 votes
1 answer

Could you please demonstrate aws lambda with python

Hey @Priyanka,  Python Lambda functions are functions that ...READ MORE

answered Jun 24, 2019 in AWS by Kalgi
• 52,350 points
848 views
+1 vote
1 answer

'No module named 'requests'' on the AWS Python Lambda function?

Hi@akhtar, For a detailed, You can even check ...READ MORE

answered Apr 15, 2020 in AWS by MD
• 95,460 points
16,834 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Pass account id of an AWS sub account using a variable as an argument in CloudWatch Alarm Actions with python (boto3)?

Python String and Integer concatenation >>> print("arn:aws:swf:us-east-2:{0}:action/actions/AWS_EC2.InstanceId.Stop/1.0".format(acccnum)) arn:aws:swf:us-east-2:12312312312312:action/actions/AWS_EC2.InstanceId.Stop/1.0 >>> print("arn:aws:swf:us-east-2:" ...READ MORE

answered Oct 5, 2018 in AWS by Priyaj
• 58,020 points
1,589 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP