-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathactivate-slack-hook.sh
executable file
·50 lines (35 loc) · 1.3 KB
/
activate-slack-hook.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
#!/bin/bash
set -e
STACK_NAME="$1"
if [ -z "$STACK_NAME" ]
then
echo "STACK_NAME is empty, you must set one to use this script"
exit 1;
fi
echo "Stack name: $STACK_NAME"
export AWS_IDENTITY=$(aws sts get-caller-identity --query 'Account' --output text)
echo "AWS Identity: $AWS_IDENTITY"
STAGE=$( aws cloudformation describe-stacks --stack-name $STACK_NAME |jq -r '.Stacks[] | select (.StackName == "'$STACK_NAME'").Tags[] | select (.Key == "STAGE").Value' )
STACK_ID=$( aws cloudformation list-stacks --stack-status-filter UPDATE_COMPLETE UPDATE_ROLLBACK_COMPLETE |jq '.StackSummaries[] | select(.StackName == "'$STACK_NAME'").StackId' -r)
if [ -z "$STAGE" ]
then
echo "STAGE is empty. Is the Cloud Formation Stack created?"
exit 1;
fi
if [ -z "$STACK_ID" ]
then
echo "STACK_ID is empty. Is the Cloud Formation stack valid?"
exit 1;
fi
LAMBDA_NAME="$STACK_NAME-$STAGE-notify"
echo "Lambda name: $LAMBDA_NAME"
LAMBDA_ARN=$(aws lambda get-function --function-name $LAMBDA_NAME |jq -r .Configuration.FunctionArn)
echo "Lambda ARN: $LAMBDA_ARN"
if [ -z "$LAMBDA_ARN" ]
then
echo "LAMBDA_ARN is empty. Cannot set slack hook"
exit 1;
fi
SLACK_URL=$(cat slack-url.txt)
echo $SLACK_URL
TAGIT=$(aws lambda tag-resource --resource $LAMBDA_ARN --tags slackhook=$SLACK_URL)