简体   繁体   中英

How to use tweepy python library as aws lambda layer?

I am following this instructions to create an AWS Lambda layer:

mkdir my-lambda-layer && cd my-lambda-layer
mkdir -p aws-layer/python/lib/python3.8/site-packages
pip3 install tweepy --target aws-layer/python/lib/python3.8/site-packages
cd aws-layer

I zip then the folder "python" ( zip -r tweepy_layer.zip python/ ) and upload it to s3. This is what I see when I unzip the folder to double check:

在此处输入图像描述 Unfortunately, I still get the following error though the pass should be the same as in the docs. I tried both from MacOs and Ubuntu though I do not think this should play a role for this particular library.

在此处输入图像描述

Essentially the problem turned out to be the cache. Yes, all those __pycache__ and .pyc files. Thanks to this other question I cleared the cache after installing the libraries by doing

pip3 install pyclean
pyclean .

After cleaning the cache, re-doing the zip and uploading it to s3 the lambda setup works perfectly:

在此处输入图像描述

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