serverless-python-requirements: Unable to get good binding path
Hi,
I have a serverless project that uses a couple of python libs. One of them is gdal.
My requirment.txt looks like this
numpy xarray boto3 gdal 
and part of my serverless.yml looks like this

When I have dockerizePip: true or dockerizePip: no linux deploying with sls deploy I get below error

If I set  dockerizePip: false  and do ‘sls deploy’  I get below error

If I remove gdal from the requiment.txt and set dockerizePip: false  and do ‘sls deploy’ it works fine but the function will not have gdal on AWS.
This is in packages.json     "serverless-python-requirements": "^4.1.1"
I have docker installed on windows.

About this issue
- Original URL
- State: open
- Created 6 years ago
- Comments: 20 (6 by maintainers)
For anyone coming from the internet looking to get GDAL working with Serverless, you should know that I went through hell and back trying to get it to work messing around with Docker containers and using @dev360’s outline as a rough guide.
However, there’s a much easier way now that AWS Lambda supports layers. Simply use one of the prebuilt layers made by https://github.com/developmentseed/geolambda at runtime to provide all of GDAL’s dependencies. For your dev environment, specify one of the images from that project that contain Python. The plugin will use the image to create a container to compile the module bindings within at build time, and
serverless deploywill link the preexisting layer to your lambda so that the bindings can seamlessly load the GDAL library binaries from the layer’s filesystem at runtime. It Just Works™️.Here’s what my
serverless.ymllooks like:I don’t know if this would be worth anything to you guys, but I found a workaround that was a little bit elaborate and it works in my particular case (django + postgis, gdal).
dockerizePip: truelambci/lambda:build-python3.6and reference that image in your serverless pythonRequirements config via thedockerImageattribute. To find the name, do adocker-compose buildand look up the name withdocker images.Dockerfile; similar to here. This gets the gdal/geos/proj C deps built and creates .so files that will be available under/tmp/app/local/libthat are built for the correct architecture.vendor: ./serverless-vendorsetting to thepythonRequirementssection inserverless.yml… this will copy your local folder calledserverless-vendorinto the sitepackages directory so its available at runtime and thus can be linked to.docker-compose run --rm [your docker image name] bashinto your docker image and copy the/tmp/app/local/lib/files into the./serverless-vendor/[your name]folder we referenced earlier.GDAL_LIBRARY_PATHin Django’ssettings.py. I’d wager theres some similar way to point gdal to the so file - it would be a matter of looking at what geo django does under the hood with this variable.Also worth noting - read carefully:
serverless-vendorfolder - I ended up importing some pip dep and going..from there to find the folder that had thelibgdal.sofile.Hope this is useful to anyone. Experience with serverless+python so far hasn’t been for the faint of heart 😃
Yeah. One issue after another. Looking into this option to see. https://github.com/joshtkehoe/lambda-python-gdal