-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.sh
69 lines (61 loc) · 1.81 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
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
# Check if the AWS CLI is in the PATH
found=$(which aws)
if [ -z "$found" ]; then
echo "Please install the AWS CLI under your PATH: http://aws.amazon.com/cli/"
exit 1
fi
# Check if jq is in the PATH
found=$(which jq)
if [ -z "$found" ]; then
echo "Please install jq under your PATH: http://stedolan.github.io/jq/"
exit 1
fi
# Read other configuration from config.json
REGION=$(jq -r '.REGION' config.json)
CLI_PROFILE=$(jq -r '.CLI_PROFILE // empty' config.json)
BUCKET=$(jq -r '.BUCKET' config.json)
MAX_AGE=$(jq -r '.MAX_AGE' config.json)
IDENTITY_POOL_ID=$(jq -r '.IDENTITY_POOL_ID' config.json)
DEVELOPER_PROVIDER_NAME=$(jq -r '.DEVELOPER_PROVIDER_NAME' config.json)
#if a CLI Profile name is provided... use it.
if [[ ! -z "$CLI_PROFILE" ]]; then
echo "setting session CLI profile to $CLI_PROFILE"
export AWS_DEFAULT_PROFILE=$CLI_PROFILE
fi
# Updating Lambda functions
for f in $(ls -1); do
if [[ $f != LambdAuth* ]]; then
continue
fi
echo "Updating function $f begin..."
cp config.json $f/
cd $f
zip -r $f.zip index.js config.json
aws lambda update-function-code --function-name ${f} --zip-file fileb://${f}.zip --region $REGION
rm config.json
rm $f.zip
cd ..
echo "Updating function $f end"
done
echo "Updating www content begin..."
cd www
if [ -d "edit" ]; then
rm edit/*
else
mkdir edit
fi
for f in $(ls -1 *.*); do
echo "Updating $f begin..."
sed -e "s/<REGION>/$REGION/g" \
-e "s/<IDENTITY_POOL_ID>/$IDENTITY_POOL_ID/g" \
-e "s/<DEVELOPER_PROVIDER_NAME>/$DEVELOPER_PROVIDER_NAME/g" \
$f > edit/$f
echo "Updating $f end"
done
echo "Updating www content end"
echo "Sync www content with S3 bucket $BUCKET begin..."
cd edit
aws s3 sync . s3://$BUCKET --cache-control max-age="$MAX_AGE" --acl public-read
cd ../..
echo "Sync www content with S3 bucket $BUCKET end"