Created
April 8, 2018 19:24
-
-
Save CarstVaartjes/77dbe8249d171e592bd17847f7009272 to your computer and use it in GitHub Desktop.
fb-prophet transformation for aws lambda
This file contains hidden or 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
# based on https://github.com/ryansb/sklearn-build-lambda | |
$ mkdir ~/.aws | |
$ cat >> ~/.aws/config | |
[default] | |
aws_access_key_id=YOUR_ACCESS_KEY_HERE | |
aws_secret_access_key=YOUR_SECRET_ACCESS_KEY | |
region=YOUR_REGION (such as us-west-2, us-west-1, etc) | |
rm -rf /srv/python/chalice | |
virtualenv --python=/usr/bin/python2.7 /srv/python/chalice | |
source /srv/python/chalice/bin/activate | |
pip install --upgrade pip | |
pip install -r ~/PycharmProjects/xxx/requirements/requirements.txt | |
pip install chalice | |
cd "$VIRTUAL_ENV/local/lib/python2.7/site-packages" | |
du -sh | |
du -sh * | sort -rh | head -10 | |
du -xh -d 1 * | sort -rh | head -20 | |
du -xh -d 1 pystan/* | sort -rh | head -20 | |
du -xh -d 1 scipy/* | sort -rh | head -20 | |
du -xh -d 1 fbprophet/* | sort -rh | head -20 | |
# libdir="$VIRTUAL_ENV/lib64/python2.7/site-packages/lib/" | |
# mkdir -p $VIRTUAL_ENV/lib64/python2.7/site-packages/lib || true | |
# cp /usr/lib64/atlas/* $libdir | |
# cp /usr/lib64/libquadmath.so.0 $libdir | |
# cp /usr/lib64/libgfortran.so.3 $libdir | |
echo "venv original size $(du -sh $VIRTUAL_ENV | cut -f1)" | |
find "$VIRTUAL_ENV/local/lib/python2.7/site-packages" -name "*.so" | xargs strip | |
echo "venv stripped size $(du -sh $VIRTUAL_ENV | cut -f1)" | |
find "$VIRTUAL_ENV/local/lib/python2.7/site-packages" -name "test" | xargs rm -rf | |
find "$VIRTUAL_ENV/local/lib/python2.7/site-packages" -name "tests" | xargs rm -rf | |
echo "venv tests removed size $(du -sh $VIRTUAL_ENV | cut -f1)" | |
rm -rf "$VIRTUAL_ENV/local/lib/python2.7/site-packages/pystan/stan/src" | |
rm -rf "$VIRTUAL_ENV/local/lib/python2.7/site-packages/pystan/stan/lib/stan_math/lib" | |
echo "venv source codes removed size $(du -sh $VIRTUAL_ENV | cut -f1)" | |
find "$VIRTUAL_ENV/local/lib/python2.7/site-packages" -name "*.py" | xargs python -m py_compile | |
find "$VIRTUAL_ENV/local/lib/python2.7/site-packages" -name "*.py" | xargs rm -f | |
echo "venv py files compiled size $(du -sh $VIRTUAL_ENV | cut -f1)" | |
find "$VIRTUAL_ENV/local/lib/python2.7/site-packages" -name "*.json" | xargs rm -f | |
echo "json files removed size $(du -sh $VIRTUAL_ENV | cut -f1)" | |
""" | |
import os | |
import ctypes | |
for d, _, files in os.walk('lib'): | |
for f in files: | |
if f.endswith('.a'): | |
continue | |
ctypes.cdll.LoadLibrary(os.path.join(d, f)) | |
""" | |
# pushd $VIRTUAL_ENV/lib/python2.7/site-packages/ && zip -r -9 -q /tmp/partial-venv.zip * ; popd | |
# pushd $VIRTUAL_ENV/local/python2.7/site-packages/ && zip -r -9 --out /outputs/venv.zip -q /tmp/partial-venv.zip * ; popd | |
# echo "site-packages compressed size $(du -sh /outputs/venv.zip | cut -f1)" | |
# pushd $VIRTUAL_ENV && zip -r -q /outputs/full-venv.zip * ; popd | |
# echo "venv compressed size $(du -sh /outputs/full-venv.zip | cut -f1)" | |
# pushd $VIRTUAL_ENV && zip -r -q /outputs/full-venv.zip * ; popd | |
# zip -r -q /outputs/full-venv.zip |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Try pystan==2.18
Also: https://medium.com/@marc.a.metz/docker-run-rm-it-v-pwd-var-task-lambci-lambda-build-python3-7-bash-c7d53f3b7eb2