0

I'm trying to install Pyproj into Lambda. To do so, I've used this code:

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

All worked okay and the layer appears in Lambda, which I've added to my function.

I then try to call it using the import pyproj command and I'm getting this error

Response
{
  "errorMessage": "Unable to import module 's3_asset_function'"
}

Function Logs
START RequestId: aece5dcf-9fa6-4557-9682-effffffb6d7c Version: $LATEST
Unable to import module 's3_asset_function': No module named 'pyproj'

There were no issues in zipping up and publishing the layer, and I've tried importing pyproj in my virtual environment via the python interpreter and it worked. So I'm stumped as to where the issue is with it not being able to be called in Lambda.

  • Did you create a proper requirement.txt with all the dependancies? Also the build has to be done against the correct environment similar to the lambda containers. I am using the following docker to build lambci/lambda – Tobias Bruckert May 28 '21 at 11:53

1 Answers1

0

The zip file must contain a folder named "python" and that folder must contain the libraries. View the exact structure here: https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html#configuration-layers-path

Example file structure for the Pillow library

pillow.zip
│ python/PIL
└ python/Pillow-5.3.0.dist-info

It looks like you are missing that folder inside your zip.

Shawn
  • 8,374
  • 5
  • 37
  • 60