简体   繁体   中英

Install PyProj as a layer in AWS Lambda

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM