Skip to content

Instantly share code, notes, and snippets.

@tuliocasagrande
Created August 18, 2020 17:35
Show Gist options
  • Save tuliocasagrande/c52b3ff067ce1bb08a1da09630caafd0 to your computer and use it in GitHub Desktop.
Save tuliocasagrande/c52b3ff067ce1bb08a1da09630caafd0 to your computer and use it in GitHub Desktop.
#!/bin/bash
library=pandas
artifacts_bucket=<MY_ARTIFACTS_BUCKET>
echo "Making sure we have the latest packages"
yum update -y
echo "Installing python3 and pip"
yum install python3 -y # this is currently python3.7
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py
echo "Creating target directory"
mkdir -p build/python/lib/python3.7/site-packages
cd build
echo "Installing $library"
/usr/local/bin/pip install $library -t python/lib/python3.7/site-packages/
echo "Compressing current directory into $library.zip"
zip -q -r $library.zip .
echo "Uploading to bucket $artifacts_bucket"
aws s3 cp $library.zip s3://$artifacts_bucket/layers/
echo "Publishing lambda layer"
yum install -y jq # the instance was lacking region information
REGION=`curl -s http://169.254.169.254/latest/dynamic/instance-identity/document | jq .region -r`
aws lambda publish-layer-version \
--layer-name $library \
--content "S3Bucket=$artifacts_bucket,S3Key=layers/$library.zip" \
--compatible-runtimes python3.7 \
--region $REGION
echo "Shuting down instance from inside"
shutdown now
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment