This repository has been archived by the owner on Dec 21, 2020. It is now read-only.
forked from aws/aws-health-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshd-notifier.yml
297 lines (296 loc) · 8.73 KB
/
shd-notifier.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
---
AWSTemplateFormatVersion: "2010-09-09"
Parameters:
AppName:
Description: SHD Health Event Application
Type: String
Default: Health-Event
ChatClient:
Description: Which notification client to use
Type: String
Default: chime
AllowedValues:
- chime
- slack
- sns
MessagePrefix:
Description: Prefix for chat messages
Type: String
Default: "[SHD AUTO]"
EndpointArray:
Description: Array of Webhook/endpoints for the selected notification client
Type: String
Bail:
Description: Skip delivery of messages with no updates
Type: Number
Default: 1
AllowedValues:
- 0
- 1
DEBUG:
Description: Enable Debugging
Type: Number
Default: 0
AllowedValues:
- 0
- 1
LambdaRate:
Description: >
The rate (frequency) that determines when CloudWatch Events runs the rule that
triggers the Lambda function.
Default: rate(1 minute)
AllowedValues:
- rate(1 minute)
- rate(5 minutes)
- rate(10 minutes)
Type: String
RegionFilter:
Description: Array of regions of interest used to filter events
Type: String
Default: "[]"
Conditions:
CreateSNSResources: !Equals [ !Ref ChatClient, sns ]
Resources:
LambdaSchedule:
Type: AWS::Events::Rule
Properties:
Description: Schedule to poll for SHD Events
ScheduleExpression: !Ref LambdaRate
State: ENABLED
Targets:
- Arn: !GetAtt EventPoller.Arn
Id: LambdaSchedule
LambdaSchedulePermission:
Type: "AWS::Lambda::Permission"
Properties:
Action: 'lambda:InvokeFunction'
FunctionName: !Sub ${EventPoller.Arn}
Principal: 'events.amazonaws.com'
SourceArn: !Sub ${LambdaSchedule.Arn}
StatesExecutionRole:
Type: AWS::IAM::Role
Properties:
Path: "/"
Policies:
- PolicyName: StatesExecutionPolicy
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- "lambda:InvokeFunction"
Resource: "*"
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Principal:
Service:
- !Sub states.${AWS::Region}.amazonaws.com
Action: "sts:AssumeRole"
LambdaRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
Service: lambda.amazonaws.com
Action: "sts:AssumeRole"
Policies:
- PolicyName: LambdaHealthPolicy
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- "health:Describe*"
Resource: "*"
- PolicyName: LambdaSNSPolicy
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- "SNS:Publish"
Resource: "*"
- PolicyName: LambdaStatesPolicy
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- "states:StartExecution"
Resource: "*"
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
PostFunction:
Type: AWS::Lambda::Function
Properties:
Description: Posts messages to chime, slack or sns topics
FunctionName: !Sub ${AppName}-Chat-Post
Handler: index.lambda_handler
MemorySize: 128
Role: !GetAtt "LambdaRole.Arn"
Runtime: python3.7
Timeout: 30
Environment:
Variables:
DEBUG: !Ref DEBUG
MESSAGEPREFIX: !Ref MessagePrefix
CHATCLIENT: !Ref ChatClient
ENDPOINTARRAY: !Ref EndpointArray
BAIL_NOCHANGE: !Ref Bail
Code:
ZipFile: |
import os
def lambda_handler(event):
print("coming soon")
EventPoller:
Type: AWS::Lambda::Function
Properties:
Description: Polls SHD for new events
FunctionName: !Sub ${AppName}-Poller
Handler: index.lambda_handler
MemorySize: 128
Role: !GetAtt LambdaRole.Arn
Runtime: python3.7
Timeout: 30
Environment:
Variables:
SFN_ARN: !Ref SHDChecker
DEBUG: !Ref DEBUG
REGION_FILTER: !Ref RegionFilter
Code:
ZipFile: |
import os
def lambda_handler(event):
print("coming soon")
EventStatusFunction:
Type: AWS::Lambda::Function
Properties:
Description: Gets the current status of a SHD event
FunctionName: !Sub ${AppName}-Status
Handler: index.lambda_handler
MemorySize: 128
Role: !GetAtt LambdaRole.Arn
Runtime: python3.7
Timeout: 30
Code:
ZipFile: |
import os
def lambda_handler(event):
print("coming soon")
IteratorFunction:
Type: AWS::Lambda::Function
Properties:
Description: Counter to decide when the health check sfn should finish
FunctionName: !Sub ${AppName}-Iterator
Handler: index.lambda_handler
MemorySize: 128
Role: !GetAtt LambdaRole.Arn
Runtime: python3.7
Timeout: 30
Code:
ZipFile: |
import os
def lambda_handler(event):
print("coming soon")
SHDChecker:
Type: "AWS::StepFunctions::StateMachine"
Properties:
DefinitionString: !Sub
- |-
{
"Comment": "A state machine that monitors open AWS health issues and posts them every 15 minutes until they are closed. When closed it sends one last final closed post.",
"StartAt": "Post Event Status",
"States": {
"Post Event Status": {
"Type": "Task",
"Resource": "${postFunction}",
"ResultPath": "$.lastUpdatedTime",
"Next": "Wait 60 Seconds",
"Retry": [
{
"ErrorEquals": ["States.ALL"],
"IntervalSeconds": 1,
"MaxAttempts": 3,
"BackoffRate": 2
}
]
},
"Wait 60 Seconds": {
"Type": "Wait",
"Seconds": 60,
"Next": "Get Event Status"
},
"Get Event Status": {
"Type": "Task",
"Resource": "${eventStatusFunction}",
"Next": "Event Complete?",
"ResultPath": "$.status",
"Retry": [
{
"ErrorEquals": ["States.ALL"],
"IntervalSeconds": 1,
"MaxAttempts": 3,
"BackoffRate": 2
}
]
},
"Event Complete?": {
"Type": "Choice",
"Choices": [
{
"Variable": "$.status",
"StringEquals": "closed",
"Next": "Post Final Event Status"
}
],
"Default": "Iterator"
},
"Iterator": {
"Type": "Task",
"Resource": "${iteratorFunction}",
"Next": "Time to post again?",
"ResultPath": "$.count",
"Retry": [
{
"ErrorEquals": ["States.ALL"],
"IntervalSeconds": 1,
"MaxAttempts": 3,
"BackoffRate": 2
}
]
},
"Time to post again?": {
"Type": "Choice",
"Choices": [
{
"Variable": "$.count",
"NumericEquals": 0,
"Next": "Post Event Status"
}
],
"Default": "Wait 60 Seconds"
},
"Post Final Event Status": {
"Type": "Task",
"Resource": "${postFunction}",
"End": true,
"Retry": [
{
"ErrorEquals": ["States.ALL"],
"IntervalSeconds": 1,
"MaxAttempts": 3,
"BackoffRate": 2
}
]
}
}
}
- postFunction: !GetAtt PostFunction.Arn
eventStatusFunction: !GetAtt EventStatusFunction.Arn
iteratorFunction: !GetAtt IteratorFunction.Arn
RoleArn: !GetAtt StatesExecutionRole.Arn