-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathbuild.sh
More file actions
64 lines (55 loc) · 1.53 KB
/
Copy pathbuild.sh
File metadata and controls
64 lines (55 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
# VirtualEnv vars
VENV="_venv"
VENV_LIBS=${VENV}/lib/python2.7/site-packages
BASE=`pwd`
#Build Vars
NOW=`date`
SUFFIX=`date -j -f "%a %b %d %T %Z %Y" "${NOW}" "+%s"`
PACKAGE_NAME="cloudfront-log-ingester-${SUFFIX}"
SERVICE_FILE="lambda_function.py"
BUILDLOG="${BASE}/build-${SUFFIX}.log"
function cleanup {
echo "Destroying environment...."
rm -rf ./${VENV}
rm -rf ./*.zip
rm -rf ./*.log
}
function setup { # -> Creates a new vurtual python enviroment
echo "[+] Creating environment \n [$NOW]" >> ${BUILDLOG}
cd ${BASE}
virtualenv ${VENV} >> ${BUILDLOG}
source ${VENV}/bin/activate >> ${BUILDLOG}
pip install elasticsearch >> ${BUILDLOG}
pip install aws_requests_auth >> ${BUILDLOG}
mkdir ${VENV}/dist >> ${BUILDLOG}
}
function build {
# -> Packages lambda function into acceptable ZIP format
echo "[+] Building Lambda package at ${BASE}/${PACKAGE_NAME}.zip [$NOW]" >> ${BUILDLOG}
rm -rf ${VENV}/dist/* >> ${BUILDLOG}
cp -R ${VENV_LIBS}/* ${VENV}/dist/ >> ${BUILDLOG}
cp ${SERVICE_FILE} ${VENV}/dist/ >> ${BUILDLOG}
cd ${VENV}/dist && zip -r ${BASE}/${PACKAGE_NAME}.zip * >> ${BUILDLOG}
echo "${PACKAGE_NAME}.zip"
}
usage="$(basename "$0") [-h] [-bcs] -- Build Lambda Function
where:
-h show this help text
-b build
-c cleanup
-s setup"
while getopts ':hbsc' option; do
case "$option" in
h) echo "$usage"
exit
;;
b) build
;;
c) cleanup
;;
s) setup
;;
esac
done
shift $((OPTIND - 1))