-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.sh
executable file
·155 lines (114 loc) · 3.58 KB
/
build.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/bin/bash
# Globals
declare -r CLOUDFORMATION_DIR="cloudformation"
declare -r DD_CF_TEMPLATE_FILE="dd.yaml"
declare -r REGION_VIRGINIA="us-east-1"
declare -r REGION_OHIO="us-east-2"
declare -r STACK_NAME="dynamodb-stack"
declare -r POC_NAME="Your Name"
declare -r DEPLOYMENT_ENVIRONMENT="dev"
declare -r DEFAULT_TABLE_NAME="EchoMessages"
declare _deployment_region=${REGION_VIRGINIA}
declare _deployment_environment=${DEPLOYMENT_ENVIRONMENT}
deploy_dd() {
echo "Deploying DynamoDb stack"
aws --region ${_deployment_region} cloudformation deploy \
--template-file ${CLOUDFORMATION_DIR}/${DD_CF_TEMPLATE_FILE} \
--stack-name ${_deployment_environment}-${STACK_NAME} \
--capabilities CAPABILITY_IAM \
--parameter-overrides "POCNameParameter=${POC_NAME}" \
"EnvironmentParameter=${_deployment_environment}" \
"TableNameParameter=${_deployment_environment}-${DEFAULT_TABLE_NAME}" \
--debug
}
list_exports(){
echo
echo " ******************* Exports ************************************* "
echo
aws cloudformation list-exports
echo
echo " ******************************************************************* "
echo
}
display_usage() {
echo
echo "-----------------------------------------------------------------------"
echo " Usage: `basename $0` [dev | test | prod] [va | oh] dd "
echo " "
echo " Example: ./build.sh test va dd # Deploy test environment dynamodb table in us-east-1"
echo "-----------------------------------------------------------------------"
}
print_script_complete() {
echo
echo "-------------------------------------------------"
echo "- Script Complete -"
echo "-------------------------------------------------"
}
set_region() {
case $1 in
va)
_deployment_region=${REGION_VIRGINIA}
echo "Deployment Region = " ${_deployment_region}
;;
oh)
_deployment_region=${REGION_OHIO}
echo "Deployment Region = " ${_deployment_region}
;;
*)
echo "Setting region to " ${REGION_VIRGINIA}
_deployment_region=${REGION_VIRGINIA}
echo "Deployment Region = " ${_deployment_region}
esac
}
set_environment() {
case $1 in
dev)
_deployment_environment="dev"
echo "Deployment Environment = " ${_deployment_environment}
;;
test)
_deployment_environment="test"
echo "Deployment Environment = " ${_deployment_environment}
;;
prod)
_deployment_environment="prod"
echo "Deployment Environment = " ${_deployment_environment}
;;
*)
_deployment_environment="dev"
echo "Deployment Environment = " ${_deployment_environment}
;;
esac
}
deploy_cloudformation_script() {
case $1 in
dd)
deploy_dd
list_exports
;;
*)
display_usage
esac
}
validate_template(){
echo "Validating CF Template: " ${CLOUDFORMATION_DIR}/${DD_CF_TEMPLATE_FILE}
aws cloudformation validate-template --template-body file://${CLOUDFORMATION_DIR}/${DD_CF_TEMPLATE_FILE}
}
process_arguments() {
#process first argument
set_environment $1; shift
#process second argument
set_region $1; shift
#process third argument
deploy_cloudformation_script $1
}
main() {
if [ "$#" -ne 3 ]; then
display_usage
exit 1
fi
process_arguments $1 $2 $3
print_script_complete
exit 1
}
main "$@"