/
deploy.sh
executable file
·47 lines (39 loc) · 905 Bytes
/
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
#!/bin/bash
# dev: ./deploy.sh
# prod: ./deploy.sh prod
STAGE=${1:-dev}
PROJECT=sbaapi-$STAGE
BUCKET=$PROJECT-12152018
make
# make a build directory to store artifacts
rm -rf build
mkdir build
# make the deployment bucket in s3 if it does not exist
aws s3 mb s3://$BUCKET
if [[ $? != 0 ]]
then
echo "FAILED WHEN CREATING AN S3 BUCKET"
exit 1
fi
# generate next stage yaml file
aws cloudformation package \
--template-file template.yaml \
--output-template-file build/output.yaml \
--s3-bucket $BUCKET
if [[ $? != 0 ]]
then
echo "FAILED DURING YAML GENERATION"
exit 1
fi
# the actual deployment step
aws cloudformation deploy \
--template-file build/output.yaml \
--stack-name $PROJECT \
--capabilities CAPABILITY_IAM \
--parameter-overrides ENVIRONMENT=$STAGE
if [[ $? != 0 ]]
then
echo "FAILED DURING CLOUDFORMATION DEPLOYMENT"
exit 1
fi
exit 0