Skip to content

Instantly share code, notes, and snippets.

@christianklotz
Created October 17, 2016 09:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christianklotz/ccd0515372abd6845b445d6ff3e61c80 to your computer and use it in GitHub Desktop.
Save christianklotz/ccd0515372abd6845b445d6ff3e61c80 to your computer and use it in GitHub Desktop.
Create Python app package for Amazon AWS Lambda including Google's ortools dependencies
#!/bin/bash
DEST_DIR=$(dirname $(realpath -s $0));
echo "Copy all native libraries...";
mkdir -p ./lib && find $directory -type f -name "*.so" | xargs cp -t ./lib;
echo "Create package...";
zip -r dist.zip your-python-script.py lib;
rm -r ./lib;
echo "Add dependencies from $VIRTUAL_ENV to $DEST_DIR/dist.zip";
cd $VIRTUAL_ENV/lib/python2.7/site-packages;
zip -ur $DEST_DIR/dist.zip ./**;
# ortools isn't found by Lamda with this setup, so instead of the line above
# I also tried the following approach, moving ortools directly into the
# project root. This works to the extend that it finds the ortools but it is
# still unable to import pywrapcp.
# Hence the following lines are purely included for illustration purposes.
#
# zip -ur $DEST_DIR/dist.zip ./**; -x "ortools*";
#
# cd $(find $directory -type d -name "ortools")/..;
# zip -ur $DEST_DIR/dist.zip ortools;
cd $VIRTUAL_ENV/src/jal;
zip -ur $DEST_DIR/dist.zip ./**;
echo "Done";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment