This repository has been archived by the owner on Oct 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
deploy.sh
executable file
·56 lines (48 loc) · 1.7 KB
/
deploy.sh
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
#!/bin/bash
FUNCTION_NAME=$(cat config/function_name)
ALLOWED_ENDPOINTS=$(cat config/allowed_endpoints)
RANGE_UPPER_LIMIT=$(cat config/range_upper_limit)
PACKAGE_DIR="clio_lite_lambda"
set -e
set -x
# Run tests
pytest
# Get latest code version
VERSION=$(python -c "import re, sys; print(max(int(x) for x in re.findall('refs\/tags\/v([0-9]+)', ' '.join(sys.argv[1:]))))" $(git for-each-ref refs/tags --format='%(refname)'))
# Check if lambda exists
set +e
set +x
aws lambda get-function --function-name $FUNCTION_NAME:Version$VERSION &> /dev/null
if [ $? -ne 0 ]
then
echo "Version $VERSION not found"
# Deploy new lambda version
OLDPWD=$PWD
mkdir $PACKAGE_DIR &> /dev/null
pip install -r requirements.txt --target ./$PACKAGE_DIR
cp clio_lite.py $PACKAGE_DIR
cp clio_utils.py $PACKAGE_DIR
cp clio_lite_searchkit_lambda.py $PACKAGE_DIR
cd $PACKAGE_DIR
zip -r9 ${OLDPWD}/clio_lite.zip .
cd ${OLDPWD}
rm -rf $PACKAGE_DIR
PYCODE_="import sys, json; print(json.load(sys.stdin)['Version'])"
FUNCTION_VERSION=$(aws lambda update-function-code \
--function-name $FUNCTION_NAME \
--zip-file fileb://clio_lite.zip \
--publish | python -c "$PYCODE_")
rm clio_lite.zip
# Set the new alias
echo "Created lambda function with pseudoversion $FUNCTION_VERSION"
aws lambda create-alias \
--function-name $FUNCTION_NAME \
--name Version$VERSION \
--function-version=$FUNCTION_VERSION
# Pick up the allowed endpoints
aws lambda update-function-configuration \
--function-name $FUNCTION_NAME \
--environment Variables="{ALLOWED_ENDPOINTS=$ALLOWED_ENDPOINTS,RANGE_UPPER_LIMIT=$RANGE_UPPER_LIMIT}"
else
echo "Nothing to do for version $VERSION"
fi