Search code examples
pythonaws-lambdaaws-lambda-layers

Uploading Python module as AWS Lambda Layer


I am looking to upload the Python module Shapely as a layer for my AWS Lambda. To do this, I have done these steps

mkdir folder
cd folder
virtualenv --python=python3.6 v-env 
source ./v-env/bin/activate
pip3 install shapely
deactivate
mkdir shapely
cd shapely 
cp -r ../v-env/lib/python3.6/site-packages/* .
cd ..
zip -r shapely.zip shapely
aws lambda publish-layer-version --layer-name shapely --zip-file fileb://shapely.zip --compatible-runtimes python3.6

The layer has successfully uploaded and I've added it to my Lambda but when I try and run it, I get the error No module named 'shapely'

I'm stuck as to where I've gone wrong as during the publishing of the layer I got no errors. Can anyone advise?


Solution

  • Using the folder name shapely would not work since according to the documentation, you should either name it python or python/lib/python<version_number>/site-packages