forked from yvele/aws-cfn-custom-resource-lambda-edge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·98 lines (77 loc) · 2.93 KB
/
install.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env bash
set -e
# Parse script parameters
while [[ "$#" -gt 0 ]]; do
case $1 in
--region) REGION="$2"; shift;;
--package-bucket) PACKAGE_BUCKET="$2"; shift;;
*) echo "Unknown parameter: $1"; exit 1;;
esac
shift
done
if [ -z "$REGION" ]; then
echo "Region parameter is not set"
exit 1
fi
if [ -z "$PACKAGE_BUCKET" ]; then
echo
echo " ================================================================="
echo " 0. Prerequisite"
echo " --------------------------"
echo " Deploy the S3 bucket that will host local artifacts uploaded by"
echo " CloudFormation when packing in ${REGION}."
echo " ================================================================="
aws cloudformation deploy \
--region ${REGION} \
--template-file stacks/package-bucket/cloudformation.yml \
--stack-name package-bucket \
--no-fail-on-empty-changeset
PACKAGE_BUCKET=$(aws cloudformation describe-stack-resource \
--region ${REGION} \
--stack-name package-bucket \
--logical-resource-id Bucket \
--output text \
--query StackResourceDetail.PhysicalResourceId)
echo "Deployed S3 bucket name: ${PACKAGE_BUCKET}"
fi
echo
echo " ================================================================="
echo " 1. us-east-1 deployment"
echo " --------------------------"
echo " Deploy the bucket that will host Lambda@Edge code in us-east-1"
echo " ================================================================="
aws cloudformation deploy \
--region us-east-1 \
--template-file stacks/lambda-edge-code-bucket/cloudformation.yml \
--stack-name lambda-edge-code-bucket \
--no-fail-on-empty-changeset
LAMBDA_EDGE_CODE_BUCKET=$(aws cloudformation describe-stack-resource \
--region us-east-1 \
--stack-name lambda-edge-code-bucket \
--logical-resource-id Bucket \
--output text \
--query StackResourceDetail.PhysicalResourceId)
echo
echo " ================================================================="
echo " 2. ${REGION} deployment"
echo " --------------------------"
echo " Deploy the CloudFormation custom resource in ${REGION}"
echo " ================================================================="
echo
echo "Pack CloudFormation template and upload artifacts to ${PACKAGE_BUCKET} in ${REGION}"
mkdir -p tmp/custom-resource-lambda-edge
aws cloudformation package \
--region ${REGION} \
--template-file stacks/custom-resource-lambda-edge/cloudformation.yml \
--output-template-file tmp/custom-resource-lambda-edge/cloudformation.yml \
--s3-bucket ${PACKAGE_BUCKET} \
--s3-prefix cloudformation/custom-resource-lambda-edge
echo "Deploy CloudFormation template in ${REGION}"
aws cloudformation deploy \
--region ${REGION} \
--template-file tmp/custom-resource-lambda-edge/cloudformation.yml \
--stack-name custom-resource-lambda-edge \
--capabilities CAPABILITY_IAM \
--no-fail-on-empty-changeset \
--parameter-overrides \
LambdaEdgeCodeBucket=${LAMBDA_EDGE_CODE_BUCKET}