This repository has been archived by the owner on Jun 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdeploy.sh
executable file
·50 lines (42 loc) · 1.84 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
#!/usr/bin/env bash
function usage {
cat << EOF
Usage: ${0} MONTHLY_BUDGET ACTUAL_THRESHOLD_PERCENTAGE FORECASTED_THRESHOLD_PERCENTAGE [MESSAGE_PREFIX]
Deploys a CloudFormation stack with AWS Budgets, SNS and Lambda resources that post a message to a slack channel.
MONTHLY_BUDGET is the monthly budget for all AWS costs for the account
ACTUAL_THRESHOLD_PERCENTAGE is the percentage of the budget that should trigger alerts for actual costs
FORECASTED_THRESHOLD_PERCENTAGE is the percentage of the budget that should trigger alerts for forecasted costs
MESSAGE_PREFIX an optional prefix to prepend the alert message with
On top of the parameters above, the following environment variables need to be set:
ACTUAL_COST_WEBHOOK_URL the URL for the actual cost alert channel
FORECASTED_COST_WEBHOOK_URL the URL for the forecasted cost alert channel
LAMBDA_PACKAGE_BUCKET the name of the S3 bucket to which the lambda function code has been uploaded
EOF
}
if [[ $# -le 3 ]]; then
usage
exit 1
fi
MONTHLY_BUDGET=$1
ACTUAL_THRESHOLD_PERCENTAGE=$2
FORECASTED_THRESHOLD_PERCENTAGE=$3
MESSAGE_PREFIX=$4
if [[ -z "${ACTUAL_COST_WEBHOOK_URL+x}" ]]; then
echo Environment variable ACTUAL_COST_WEBHOOK_URL should be defined
exit 2
fi
if [[ -z "${FORECASTED_COST_WEBHOOK_URL+x}" ]]; then
echo Environment variable FORECASTED_COST_WEBHOOK_URL should be defined
exit 3
fi
set -euo pipefail
sam deploy \
--template-file packaged.yaml \
--stack-name budget-alerts \
--capabilities CAPABILITY_IAM CAPABILITY_NAMED_IAM CAPABILITY_AUTO_EXPAND \
--parameter-overrides "MonthlyBudget=${MONTHLY_BUDGET}" \
"MessagePrefix=${MESSAGE_PREFIX}" \
"ActualCostWebHookUrl=${ACTUAL_COST_WEBHOOK_URL}" \
"ActualThreshold=${ACTUAL_THRESHOLD_PERCENTAGE}" \
"ForecastedCostWebHookUrl=${FORECASTED_COST_WEBHOOK_URL}" \
"ForecastedThreshold=${FORECASTED_THRESHOLD_PERCENTAGE}"