forked from guardian/cf-notify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.sh
executable file
·87 lines (70 loc) · 1.98 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
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
#!/usr/bin/env bash
if [ $# -lt 1 ]
then
echo "usage: $0 <CHANNEL> <WEBHOOK> <BUCKET> [TOPIC] [PROFILE]"
exit 1
fi
CHANNEL=$1
WEBHOOK=$2
BUCKET=$3
TOPIC=${4:-"cf-notify"}
PROFILE=${5:-"default"}
RELEASE=$(date +%Y-%m-%d-%H%M)
if [ -z $BUCKET ];
then
echo "Please specify a bucket name";
exit 1
fi
if [ -z $CHANNEL ];
then
echo "Please specify a Slack Channel e.g #general or @me";
exit 1
fi
if [ -z $WEBHOOK ];
then
echo "Please specify a Slack WebHook";
exit 1
fi
if [[ $(aws configure --profile $PROFILE list) && $? -ne 0 ]];
then
exit 1
fi
if [ ${CHANNEL:0:1} != '#' ] && [ ${CHANNEL:0:1} != '@' ];
then
echo ${CHANNEL:0:1}
echo 'Invalid Channel. Slack channels begin with # or @'
exit 1
fi
CHANNEL_NAME=`echo ${CHANNEL:1} | tr '[:upper:]' '[:lower:]'`
echo "Creating bucket $BUCKET"
aws s3 mb "s3://$BUCKET" --profile $PROFILE || exit 1
echo "Bucket $BUCKET created"
echo 'Creating lambda zip artifact'
zip -j cf-notify.zip src/*
echo 'Lambda artifact created'
echo 'Moving lambda artifact to S3'
aws s3 cp cf-notify.zip s3://$BUCKET/$RELEASE/cf-notify.zip --profile $PROFILE
rm cf-notify.zip
echo 'Lambda artifact moved'
echo 'Deleting existing stack if it exists'
aws cloudformation delete-stack --stack-name cf-notify --profile $PROFILE || true
aws cloudformation wait stack-delete-complete --stack-name cf-notify --profile $PROFILE
echo 'Stack deleted if it existed'
echo 'Creating stack'
aws cloudformation create-stack \
--template-body file://cloudformation/cf-notify.json \
--stack-name cf-notify \
--capabilities CAPABILITY_IAM \
--parameters ParameterKey=ArtifactBucket,ParameterValue=$BUCKET \
ParameterKey=Release,ParameterValue=$RELEASE \
ParameterKey=TopicName,ParameterValue=$TOPIC \
ParameterKey=SlackChannel,ParameterValue=$CHANNEL \
ParameterKey=SlackWebhook,ParameterValue=$WEBHOOK \
--profile $PROFILE \
--output text
if [[ $? != 0 ]];
then
exit 1
else
echo 'Stack created'
fi