-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtemplate.yaml
74 lines (70 loc) · 2.89 KB
/
template.yaml
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
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
aws-bills-on-slack stdout AWS bills to Slack channel
Parameters:
HeaderMessageText:
Type: String
Default: "Here's the daily bill on our AWS accounts:"
Description: 'A short text that is prefixed to Slack message. See the screenshot example here - https://github.com/toricls/aws-bills-on-slack#readme.'
MaxLength: 256
MinLength: 0
FooterMessageText:
Type: String
Default: ""
Description: 'A short text that is suffixed to Slack message.'
MaxLength: 256
MinLength: 0
OuId:
Type: String
Description: 'A Root ID or an OrganizationalUnit (OU) ID of your AWS Organization. aws-bills-on-slack fetchs the cost of AWS accounts under the specified Root or OU.'
AllowedPattern: '^(r-[0-9a-z]{4,32})|(ou-[0-9a-z]{4,32}-[a-z0-9]{8,32})$'
SlackIncomingWebhookUrl:
Type: String
Description: 'A url of Slack Incoming Webhook. See the doc to get your own - '
AllowedPattern: '^https\:\/\/hooks\.slack\.com\/.*$'
CronScheduleString:
Type: String
Description: "A cron string to run the script. The defualt value is 'cron(0 0 * * ? *)', which means the script would run at 0 AM UTC every day. See the expressions guide here - https://docs.aws.amazon.com/scheduler/latest/UserGuide/schedule-types.html#cron-based."
Default: 'cron(0 0 * * ? *)'
Globals:
Function:
Timeout: 10
Resources:
AwsBillsOnSlackFunc:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
CodeUri: ./../../ # Points the root directory of the repository
Handler: main
Runtime: go1.x
Architectures:
- x86_64
Environment: # More info about Env Vars: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#environment-object
Variables:
OU_ID: !Ref OuId
SLACK_WEBHOOK: !Ref SlackIncomingWebhookUrl
HEADER_TEXT: !Ref HeaderMessageText
FOOTER_TEXT: !Ref FooterMessageText
Policies:
- Statement:
- Sid: AllowListAccountsAndGetCosts
Effect: Allow
Action:
- organizations:ListAccountsForParent
- ce:GetCostAndUsage
Resource: '*'
Events:
EveryDayWithTimeWindow:
Type: ScheduleV2
Properties:
Description: Schedule with flexible time-window for Slack notification
FlexibleTimeWindow:
MaximumWindowInMinutes: 5
Mode: FLEXIBLE
State: ENABLED
Name: aws-bills-on-slack-schedule
ScheduleExpression: !Ref CronScheduleString
Outputs:
AwsBillsOnSlackFuncArn:
Description: "aws-bills-on-slack Lambda Function ARN"
Value: !GetAtt AwsBillsOnSlackFunc.Arn