Is it possible to correctly point to the Python library Shapely LIBGEOS_C in AWS Lambda?

I am trying to write an AWS python Lambda function that uses Shapely for simple point in polygon operations. I deployed an AWS linux EC2 instance, installed Shapely, and worked with the script. Then I downloaded linux specific libgeos_c.so.1 from my EC2 instance and linked it (through a server without a server) to exist in the same directory as my lambda function. However, after the deployment, the script will not be executed because it gives the error "I can not find the library or load any version of it ...". I even tried to explicitly specify the path libgeos_c.so.1 through the GEOS_LIBRARY_PATH environment variable so as not to affect. Is it impossible?

Here is a piece of code that sets an environment variable, and then calls a secondary script that actually imports and uses a beautiful shape.

import sys
import os
import subprocess

here = os.path.dirname(os.path.realpath(__file__))

# Import installed packages (in site-packages)
site_pkgs = os.path.join(here, "venv", "lib", "python2.7", "site-packages") 
sys.path.append(site_pkgs)
import json

def hello(event, context):

    command = "GEOS_LIBRARY_PATH={} python test_geo_worker.py".format(here + "/libgeos_c.so.1")
    foo = subprocess.check_output(command, shell=True)
    print foo

Is there anyone who successfully deploys in lambda? My backup plan is to get back to good old postgres / postgis instead of slim, but I would like to try building this on the dynamo / lambda stack.

+4
source share
3 answers

It is possible. Try the following steps and see if the problem persists.

First install GEOS:

yum install geos-devel.x86_64

Then Shapely:

pip2.7 install shapely

Try importing Shapely:

python2.7 -c "import shapely"
0
source

, , .

, Lambda, , - Linux, , .

, Python, Lambda, .

https://github.com/ryfeus/lambda-packs

( , pip).

0

, Shapely -. https://github.com/bearflagrobotics/libgeos-lambda-build, Amazon Shapely C++ Lambda. zip Python/Shapely

0
source

Source: https://habr.com/ru/post/1663802/


All Articles