-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathdeploy_example.sh
executable file
·63 lines (44 loc) · 2.83 KB
/
deploy_example.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
#!/bin/bash
# Authored by Runpeng Liu,
# Brain Power (2018)
# Default stack name
STACK_NAME="brain-power-fidgetology-demo"
# Only regions with both Kinesis Video Stream and Rekognition service are supported
SUPPORTED_REGIONS=("us-west-2" "us-east-1" "eu-west-1" "ap-northeast-1")
###### Do not modify below ######
containsElement () {
local e match="$1"
shift
for e; do [[ "$e" == "$match" ]] && IS_VALID_REGION='y' && return; done
return
}
REGION=$(aws configure get region)
containsElement "${REGION}" "${SUPPORTED_REGIONS[@]}"
if [ -z "$IS_VALID_REGION" ]; then
echo "Deployment in region ${REGION} is not supported. Supported regions are: [ ${SUPPORTED_REGIONS[*]} ]. Please re-configure your default region using the AWS CLI before deploying."
exit 1
fi
ACCOUNT_ID=$(aws sts get-caller-identity --output text --query 'Account')
if [ -z "$ACCOUNT_ID" ]; then
echo "Error getting account ID. Please confirm your AWS CLI is configured correctly."
exit 1
fi
BOOTSTRAP_BUCKET_NAME="${STACK_NAME}-bootstrap-${ACCOUNT_ID}"
set -e
aws s3 mb s3://${BOOTSTRAP_BUCKET_NAME}
mkdir lambda/MKVConvert/lib && cp -r lambda/_shared/* lambda/MKVConvert/lib
mkdir lambda/WebApi/lib && cp -r lambda/_shared/* lambda/WebApi/lib
# These two lines deploy the 'Full' version of the web app (with Webcam, KVS, Rekognition Video + Analytics features)
aws cloudformation package --template-file template.yaml --s3-bucket ${BOOTSTRAP_BUCKET_NAME} --output-template-file master-template.yaml
aws cloudformation deploy --template-file master-template.yaml --stack-name ${STACK_NAME} --capabilities CAPABILITY_IAM
# If wishing to deploy the 'Lite' version of the web app (which only includes Webcam and KVS),
# then comment out the two commands above and uncomment the two commands below.
# aws cloudformation package --template-file template_lite.yaml --s3-bucket ${BOOTSTRAP_BUCKET_NAME} --output-template-file packaged-template_lite.yaml
# aws cloudformation deploy --template-file packaged-template_lite.yaml --stack-name ${STACK_NAME} --capabilities CAPABILITY_IAM
API_ENDPOINT=$(aws cloudformation describe-stacks --stack-name ${STACK_NAME} --output text --query 'Stacks[0].Outputs[?OutputKey==`APIEndpoint`].OutputValue')
WEBAPP_BUCKET=$(aws cloudformation describe-stack-resources --stack-name ${STACK_NAME} --logical-resource-id WebAppBucket --output text --query 'StackResources[0].PhysicalResourceId')
WEBAPP_URL=$(aws cloudformation describe-stacks --stack-name ${STACK_NAME} --output text --query 'Stacks[0].Outputs[?OutputKey==`WebAppSecureURL`].OutputValue')
echo "const API_ENDPOINT = '${API_ENDPOINT}'" > "dashboard/js/app/config.js"
aws s3 cp dashboard/js/app/config.js s3://${WEBAPP_BUCKET}/js/app/config.js
printf "\n===================================================================\n"
printf "Deployment completed. Visit the following link to demo the web app:\n${WEBAPP_URL}\n"