How to make a Python pandas Layer for AWS Lambda
source link: https://gist.github.com/antoinedelia/4060330cb5b1bba77371b9417b921b7b
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
How to make pandas as an AWS layer
-
Install pandas to local directory with pip:
pip install -t . pandas
-
Remove pandas and numpy directories
rm -r pandas numpy
-
Download the Linux distribution for pandas (choose the Python version that you want to use): https://pypi.org/project/pandas/#files
-
Download the Linux distribution for numpy (must be the same as the pandas one): https://pypi.org/project/numpy/#files
-
Move the downloaded files to your current directory and unzip them:
unzip numpy-1.16.1-cp36-cp36m-manylinux1_x86_64.whl
andunzip pandas-0.24.1-cp36-cp36m-manylinux1_x86_64.whl
a. Note: Lambda with Python 3.7 requires pytz lib:
$ pip install -t . pytz
-
Remove unecessary files:
rm -r *.whl *.dist-info __pycache__
-
Make the following directory (change the version of Python according to what you downloaded earlier):
lambda_layers/python/lib/python3.8/site-packages/.
-
Move your whole directory into the
site-packages
folder. -
Go to
cd lambda_layers
and run:zip -r pandas_lambda_layer.zip *
-
Upload the zip to S3.
-
Create a Layer that uses the file uploaded to S3.
-
Create a Lambda function (must uses the same Python version than before).
-
You can test that everything works by using the code in
lambda_function.py
-
Have fun with pandas!
Sources:
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK