-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtemplate.yaml
88 lines (85 loc) · 2.22 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
smarter-sensibo
SAM Template to run sensibo
Globals:
Function:
Timeout: 5
Resources:
SensiboLogGroup:
Type: AWS::Logs::LogGroup
DependsOn: [SmarterSensiboFunction]
Properties:
LogGroupName: !Sub /aws/lambda/${SmarterSensiboFunction}
RetentionInDays: 7
DeadManFilter:
Type: AWS::Logs::MetricFilter
DependsOn: [SensiboLogGroup]
Properties:
FilterPattern: "SENSIBO_SETTING_SUCCESS"
LogGroupName: !Sub /aws/lambda/${SmarterSensiboFunction}
MetricTransformations:
-
MetricValue: "1"
MetricNamespace: "custom/SmarterSensibo"
MetricName: "SuccessCount"
DeadManAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmDescription: "Sensibo Setting Failure"
AlarmActions:
- !Ref Topic
MetricName: "SuccessCount"
Namespace: "custom/SmarterSensibo"
Threshold: 0
ComparisonOperator: LessThanThreshold
DatapointsToAlarm: 1
TreatMissingData: breaching
Period: 3600
EvaluationPeriods: 1
Statistic: Sum
Topic:
Type: AWS::SNS::Topic
Properties: {}
TopicPolicy:
Type: AWS::SNS::TopicPolicy
Properties:
PolicyDocument:
Id: Id1
Version: '2012-10-17'
Statement:
- Sid: Sid1
Effect: Allow
Principal:
AWS: '*' #allow cloudwatch alarms
Action: 'sns:Publish'
Resource: !Ref Topic
Condition:
StringEquals:
'AWS:SourceOwner': !Ref 'AWS::AccountId'
Topics:
- !Ref Topic
EmailSubscription:
Type: 'AWS::SNS::Subscription'
Properties:
Protocol: email
Endpoint: 'jbarratt@serialized.net'
TopicArn: !Ref Topic
SmarterSensiboFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: code/
Handler: handler
Runtime: go1.x
Environment:
Variables:
SENSIBO_API_KEY: "ssm:/keys/sensibo"
Policies:
- SSMParameterReadPolicy:
ParameterName: "keys/sensibo"
Events:
Time:
Type: Schedule
Properties:
Schedule: rate(10 minutes)