Playbook for creating AWS Lambda Layer for Python
Reference:
SSH into Linux VM (example here is Amazon Linux AMI)
Check to see Python3 version, install if necessary.
python --version
python3 --version
sudo yum list | grep python3
sudo yum install python36 python36-pip
python --version
python3 --version
sudo yum updateCreate folder structure for lambda layer.
mkdir aws-lambda-layer-v1
cd aws-lambda-layer-v1
mkdir -p lambda-layer/python/lib/python3.6/sitepackagesCreate requirements.txt file (see sample in repo).
vi requirements.txt
psycopg2-binary
pandas
requests
sklearn
numpy
matplotlib
seaborn
sqlalchemy
<Esc>:wqCreate deployment package as zip file. Remember the "." at end of zip command.
python3 -m pip install -r requirements.txt -t lambda-layer/python/lib/python3.6/site-packages
cd lambda-layer
zip -r9 lambda-layer.zip .Copy the zip file to s3 bucket. Remember the "/" at end of aws s3 cp command
aws s3 ls
aws s3 cp lambda-layer.zip s3://<BUCKET-NAME>/<FOLDER-NAME>/From AWS Lambda, paste an S3 link URL
s3://<BUCKET-NAME>/<FOLDER-NAME>/lambda-layer.zip