简体   繁体   English

在 AWS Lambda 中将 PyProj 作为层安装

[英]Install PyProj as a layer in AWS Lambda

I'm trying to install Pyproj into Lambda.我正在尝试将 Pyproj 安装到 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.一切正常,图层出现在 Lambda 中,我已将其添加到我的 function 中。

I then try to call it using the import pyproj command and I'm getting this error然后我尝试使用import pyproj命令调用它,我收到了这个错误

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.压缩和发布图层没有问题,我尝试通过 python 解释器在我的虚拟环境中导入 pyproj,它工作正常。 So I'm stumped as to where the issue is with it not being able to be called in Lambda.所以我很困惑问题出在哪里,无法在 Lambda 中调用它。

The zip file must contain a folder named "python" and that folder must contain the libraries. zip 文件必须包含一个名为“python”的文件夹,并且该文件夹必须包含库。 View the exact structure here: https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html#configuration-layers-path在此处查看确切的结构: https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html#configuration-layers-path

Example file structure for the Pillow library Pillow 库的示例文件结构

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

It looks like you are missing that folder inside your zip.看起来您在 zip 中缺少该文件夹。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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