-
Notifications
You must be signed in to change notification settings - Fork 1
/
deploy.sh
executable file
·51 lines (42 loc) · 1.65 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
#!/usr/bin/env bash
set -euo pipefail
my_dir="$(dirname "$(readlink -e "$0")")"
readonly lambda_jar="${my_dir}/server/target/awswebsocketdemo-lambda.jar"
[ -f "${lambda_jar}" ] || {
echo "lambda jar (${lambda_jar}) not present, packaging..." >&2
mvn package -DskipTests
}
find server/src/main | while read file; do
if [ "${file}" -nt "${lambda_jar}" ]; then
echo "'${file}' is newer than '${lambda_jar}', re-packaging..." >&2
mvn package -DskipTests
fi
done
readonly bucket_stack_name="${STACK_IDENTIFIER}-bucket"
readonly lambda_stack_name="${STACK_IDENTIFIER}-lambda"
readonly s3_bucket="${STACK_IDENTIFIER}-bucket"
readonly s3_key="awswebsocketdemo-lambda-$(md5sum < "${lambda_jar}" | cut -d ' ' -f 1).jar"
aws cloudformation deploy \
--no-fail-on-empty-changeset \
--stack-name "${s3_bucket}" \
--parameter-overrides \
ArtifactBucketName="${s3_bucket}" \
StackIdentifier="${STACK_IDENTIFIER}" \
--template-file cf-bucket.yml
aws s3api head-object --bucket "${s3_bucket}" --key "${s3_key}" &> /dev/null ||
aws s3 cp "${lambda_jar}" "s3://${s3_bucket}/${s3_key}"
aws cloudformation deploy \
--capabilities CAPABILITY_NAMED_IAM \
--no-fail-on-empty-changeset \
--stack-name "${lambda_stack_name}" \
--parameter-overrides \
ArtifactBucketName="${s3_bucket}" \
StackIdentifier="${STACK_IDENTIFIER}" \
ArtifactKey="${s3_key}" \
--template-file cf-lambda.yml
eval "export $(aws cloudformation describe-stacks --stack-name "${lambda_stack_name}" --output text |
grep -E "OUTPUTS" | awk '{print $3 "=" $4}' | tee /dev/stderr)"
cat <<EOF
HTTP endpoint: "${HttpEndpoint}"
Websocket endpoint: "${WebSocketEndpoint}"
EOF