Created
February 26, 2020 10:53
-
-
Save rhattersley/e930d37c32080a75ca47dde8d1e2a01d to your computer and use it in GitHub Desktop.
Iris as an AWS Lambda layer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/bin/bash | |
sudo rm -r opt | |
sudo rm -r task | |
mkdir task | |
cp container-build.sh task/ | |
docker run -v /home/ec2-user/opt:/opt -v /home/ec2-user/task:/var/task -it lambci/lambda:build-python3.7 /bin/bash container-build.sh | |
pushd opt | |
zip -r9 ../iris-layer.zip * | |
popd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/bin/bash | |
set -x | |
cd /tmp | |
yum install -y wget jq | |
# Jump-start with NumPy and SciPy from AWS | |
LAYER_ARN=$(aws lambda get-function --function-name test --region eu-west-2 | jq --raw-output .Configuration.Layers[0].Arn) | |
DOWNLOAD_URL=$(aws lambda get-layer-version-by-arn --arn "$LAYER_ARN" --region eu-west-2 | jq --raw-output .Content.Location) | |
wget -O layer.zip "$DOWNLOAD_URL" | |
unzip -d /opt layer.zip | |
# Easy pip installable dependencies | |
export PYTHONPATH=/opt/python/lib/python3.7/site-packages:$PYTHONPATH | |
export share=/opt/python/lib/python3.7/site-packages | |
pip install --no-deps --no-compile -t $share cftime netCDF4 dask toolz | |
# PyKE | |
wget -O pyke.zip http://download.sourceforge.net/pyke/pyke3-1.1.1.zip | |
unzip pyke.zip | |
pushd pyke-1.1.1 | |
python setup.py install --install-lib=$share | |
popd | |
# expat | |
wget -O expat.tar.bz2 https://github.com/libexpat/libexpat/releases/download/R_2_2_9/expat-2.2.9.tar.bz2 | |
bunzip2 expat.tar.bz2 | |
tar xvf expat.tar | |
pushd expat-2.2.9 | |
./configure --prefix=/opt | |
make install | |
popd | |
# UDUNITS-2 | |
wget -O udunits.tar.gz https://github.com/Unidata/UDUNITS-2/archive/v2.2.27.6.tar.gz | |
tar xzvf udunits.tar.gz | |
pushd UDUNITS-2-2.2.27.6 | |
autoreconf -vfi | |
./configure --prefix=/opt | |
make install | |
popd | |
# cf-units | |
export CPPFLAGS=-I/opt/include | |
export LDFLAGS=-L/opt/lib | |
pip install --no-deps --no-compile -t $share cf-units | |
# Fake Cartopy | |
mkdir $share/cartopy | |
touch $share/cartopy/__init__.py | |
touch $share/cartopy/crs.py | |
touch $share/cartopy/img_transform.py | |
# Iris! | |
wget -O iris.tar.gz https://github.com/SciTools/iris/archive/v2.3.0.tar.gz | |
tar xzvf iris.tar.gz | |
pushd iris-2.3.0 | |
pip install --no-deps --no-compile -t $share . | |
popd | |
rm -r $share/iris/tests | |
# Tidy up unwanted files | |
find /opt | grep '\.pyc$' | xargs rm | |
rm -r /opt/include | |
rm -r /opt/share/doc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment