This repository has been archived by the owner on Nov 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
/
deploy.sh
executable file
·91 lines (71 loc) · 1.7 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
88
89
90
91
#!/usr/bin/env bash
test $(which pwgen)
if [ $? != "0" ]; then
echo -e "pwgen not found. Please install using 'sudo apt-get install pwgen' (GNU/Linux) or 'brew install pwgen' (OSX)"
exit 1
fi
if [ $# -lt 1 ]
then
echo "usage: $0 <CHANNEL> <WEBHOOK> <AWS_PROFILE>"
exit 1
fi
CHANNEL=$1
WEBHOOK=$2
PROFILE=$3
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 [ -z $PROFILE ];
then
PROFILE="default"
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="cf-notify-`pwgen -1 --no-capitalize 5`"
echo $BUCKET
aws s3 mb "s3://$BUCKET" --profile $PROFILE
echo "Bucket $BUCKET created"
echo 'Creating lambda zip artifact'
if [ ! -f slack.py ]; then
cat > slack.py <<EOL
WEBHOOK='$WEBHOOK'
CHANNEL='$CHANNEL'
CUSTOM_CHANNELS={}
EOL
fi
zip cf-notify.zip lambda_notify.py slack.py
echo 'Lambda artifact created'
echo 'Moving lambda artifact to S3'
aws s3 cp cf-notify.zip s3://$BUCKET/cf-notify.zip --profile $PROFILE
rm cf-notify.zip
echo 'Lambda artifact moved'
echo 'Creating stack'
aws cloudformation create-stack \
--template-body file://cf-notify.json \
--stack-name cf-notify \
--capabilities CAPABILITY_IAM \
--parameters ParameterKey=Bucket,ParameterValue=$BUCKET \
--profile $PROFILE
if [[ $? != 0 ]];
then
exit 1
else
echo 'Stack created'
fi