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,670 points
124 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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
• 56,120 points

Related Questions In AWS

+1 vote
10 answers
+1 vote
2 answers

How do I run python script on aws EC2 instance(ubuntu)?

I believe that you are using the ...READ MORE

answered Apr 17, 2018 in AWS by Cloud gunner
• 4,240 points
1,363 views
+2 votes
3 answers
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
• 56,120 points
70 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.