Setting up Shapely on AWS Lambda Python functions

拈花ヽ惹草 提交于 2019-12-02 08:44:45

问题


I have a tried to setup Shapely on AWS Lambda but was getting the below error always.

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

Not sure how to build shapely in this case. Have built my package on Linux instance and have used the same for deployment purpose.


回答1:


If you wish to build your own Lambda compatible binaries for use in your Deployment packages, AWS states the AMI needed to build them here:

https://docs.aws.amazon.com/lambda/latest/dg/current-supported-versions.html

I have created an EC2 instance with that specific AMI and then used pip to install the packages I needed into a target folder -t. Once complete I simply tar'd that up and used it as the basis for my deployment package and it worked.

Alternatively I have downloaded from : https://github.com/ryfeus/lambda-packs and copied the packages I have needed. (Which in the case of shapley, was the shapely and shapely-1.6b4.dist-info directories.

I believe these are only built for Python 2.7 at the moment, and I have only compiled binaries with the above AMI for Python 2.7.

HTH




回答2:


I hit this same issue, and was able to set up to build a layer for use in Lambda. I wrote it up as an open source package here https://github.com/bearflagrobotics/libgeos-lambda-build using Docker to build the binary distribution. You can just drop that in as a layer for your lambda function and run any version of Shapely or Python you want!



来源:https://stackoverflow.com/questions/48190029/setting-up-shapely-on-aws-lambda-python-functions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!