-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.yml
82 lines (80 loc) · 3.06 KB
/
template.yml
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
AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
Description: A collection of utilities that integrate with Cost Explorer
Resources:
DailySlackSnapshotFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: src/daily-slack-snapshot
Description: >-
Sends daily messages to Slack with AWS billing information
Events:
Cron:
Properties:
Description: Triggers the Cost Explorer report once a day
Enabled: true
Schedule: cron(0 14 * * ? *)
Type: Schedule
Handler: lambda_function.lambda_handler
MemorySize: 512
Policies:
- Statement:
- Action: events:PutEvents
Effect: Allow
Resource: !Sub arn:${AWS::Partition}:events:${AWS::Region}:${AWS::AccountId}:event-bus/default
Sid: AllowDefaultEventBusPut
- Action:
- ce:GetCostAndUsage
- ce:GetReservationCoverage
- ce:GetReservationUtilization
- ce:GetSavingsPlansCoverage
- ce:GetSavingsPlansUtilization
Effect: Allow
Resource: "*"
Sid: AllowCostExplorerRead
Version: "2012-10-17"
Runtime: python3.10
Tags:
prx:meta:tagging-version: 2021-04-07
prx:cloudformation:stack-name: !Ref AWS::StackName
prx:cloudformation:stack-id: !Ref AWS::StackId
prx:ops:environment: Production
prx:dev:application: Cost Explorer Toolkit
Timeout: 16
DailySlackSnapshotLogGroup:
Type: AWS::Logs::LogGroup
DeletionPolicy: Delete
UpdateReplacePolicy: Delete
Properties:
LogGroupName: !Sub /aws/lambda/${DailySlackSnapshotFunction}
RetentionInDays: 14
Tags:
- { Key: prx:meta:tagging-version, Value: "2021-04-07" }
- { Key: prx:cloudformation:stack-name, Value: !Ref AWS::StackName }
- { Key: prx:cloudformation:stack-id, Value: !Ref AWS::StackId }
- { Key: prx:ops:environment, Value: Production }
- { Key: prx:dev:application, Value: Cost Explorer Toolkit }
DailySlackSnapshotErrorAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmName: "MINOR [Cost Explorer] Daily Snapshot <prod> EXPERIENCING ERRORS"
AlarmDescription: >-
The error rate on the daily Cost Explorer snapshot
Lambda function has exceeded 0.
ComparisonOperator: GreaterThanThreshold
Dimensions:
- Name: FunctionName
Value: !Ref DailySlackSnapshotFunction
EvaluationPeriods: 1
MetricName: Errors
Namespace: AWS/Lambda
Period: 60
Statistic: Sum
Tags:
- { Key: prx:meta:tagging-version, Value: "2021-04-07" }
- { Key: prx:cloudformation:stack-name, Value: !Ref AWS::StackName }
- { Key: prx:cloudformation:stack-id, Value: !Ref AWS::StackId }
- { Key: prx:ops:environment, Value: Production }
- { Key: prx:dev:application, Value: Cost Explorer Toolkit }
Threshold: 0
TreatMissingData: notBreaching