-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalarm.yaml
executable file
·366 lines (331 loc) · 13.4 KB
/
alarm.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
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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
AWSTemplateFormatVersion: "2010-09-09"
Description: >-
CFN Nested Template to create a Glue Job Trigger.
Metadata:
TemplateName: glue-trigger.yaml
TemplateType: Glue Trigger
Version: 1.0.0
Owner: Subhamay Bhattacharyya
ProjectName: Nested Stack Templates Collection
Modification History:
- 1.0.0 - Dec 31, 2024 -- Initial Version
StepsToTest: Manually verify the Stack
StepsToCleanup: Stack delete command
Parameters:
ProjectName: The Project name to be used as a resource tag value.
Environment: The Environment name to be used as a resource tag value.
GitHubRef: GitHub Ref name to be used as a resource tag value.
GitHubURL: GitHub URL to be used as a resource tag value.
GitHubWFRunNumber: The Workflow run number to be used as a resource tag value.
GitHubSHA: The sha value of the last commit to be used as a resource tag value.
GitHubRepository: The GitHub Repository name to be used as a resource tag value.
CiBuild: Ci Build of the feature branch to be appended to a resource name.
KmsMasterKeyAlias: The KMS master key alias to be used for server-side encryption.
TopicBaseName: The base name of the SNS topic. The topic name will be created by appending the environment and region.
TopicDisplayName: The SNS topic display name.
Conditions:
UseKmsMasterKey: Determines if KMS Master Key should be used based on the KmsMasterKeyAlias parameter.
Resources:
SNSTopic: Creates an SNS Topic with the specified properties and tags.
Outputs:
SNSTopicArn: The Arn of the SNS Topic.
AWS::CloudFormation::Interface:
ParameterGroups:
################################## Project Name and Environment ##############################
- Label:
default: "Project Name and Environment:"
Parameters:
- ProjectName
- Environment
################################## GitHub Attributes #########################################
- Label:
default: "GitHub Attributes:"
Parameters:
- GitHubRef
- GitHubURL
- GitHubWFRunNumber
- GitHubSHA
- GitHubRepository
- CiBuild
################################## CloudWatch Alarm ##########################################
- Label:
default: "CloudWatch Alarm Configuration:"
Parameters:
- ActionsEnabled
- SNSTopicBaseName
- AlarmBaseName
- AlarmDescription
- ComparisonOperator
- MetricName
- MetricNamespace
- AlarmPeriod
- MetricStatistic
- AlarmThreshold
- MetricUnit
- TreatMissingData
- DatapointsToAlarm
- EvaluationPeriods
- DimensionName
- DimensionValue
ParameterLabels:
################################## Project Name and Environment ##############################
ProjectName:
default: "Name of the Project."
Environment:
default: "Name of the Deployment Environment."
################################## GitHub Attributes #########################################
GitHubRef:
default: "GitHub Reference Branch or Tag."
GitHubURL:
default: "URL of the GitHub Repository."
GitHubWFRunNumber:
default: "GitHub Workflow Execution Run Number."
GitHubSHA:
default: "GitHub Commit SHA."
GitHubRepository:
default: "Name of the GitHub Repository."
CiBuild:
default: "Continuous Integration Build Identifier."
################################## CloudWatch Alarm ##########################################
ActionsEnabled:
default: "Enable Actions."
SNSTopicBaseName:
default: "Base name of the SNS Topic."
AlarmBaseName:
default: "Base name of the CloudWatch Alarm."
AlarmDescription:
default: "Description of the CloudWatch Alarm."
ComparisonOperator:
default: "Comparison Operator."
MetricName:
default: "Name of the CloudWatch Metric."
MetricNamespace:
default: "Namespace of the CloudWatch Metric."
AlarmPeriod:
default: "Period of the CloudWatch Metric."
MetricStatistic:
default: "Statistic of the CloudWatch Metric."
AlarmThreshold:
default: "Threshold of the CloudWatch Metric."
MetricUnit:
default: "Unit of the CloudWatch Metric."
TreatMissingData:
default: "Treat Missing Data."
DatapointsToAlarm:
default: "The number of datapoints to alarm."
EvaluationPeriods:
default: "The number of periods to evaluate."
DimensionName:
default: "The name of the dimension."
DimensionValue:
default: "The value of the dimension."
Parameters:
###################################### Project Name and Environment ##############################
ProjectName:
Default: app01-proj-1
Description: "The Project name to be used as a resource tag value."
Type: String
MinLength: 5
MaxLength: 30
AllowedPattern: "^[a-z0-9-]+$"
ConstraintDescription: "The length should be between 5 and 30, must contain only lowercase alphabets, numbers, or dashes."
Environment:
Default: devl
Description: "The Environment name to be used as a resource tag value."
Type: String
AllowedValues: ["devl", "test", "prod"]
ConstraintDescription: "The Environment must be devl / test or prod"
###################################### GitHub Attributes #########################################
GitHubRef:
Default: ref_name
Description: "GitHub Ref name to be used as a resource tag value."
Type: String
AllowedPattern: "^[a-zA-Z0-9/_-]+$"
ConstraintDescription: "The GitHub Ref Name can only contain alphanumeric characters, slashes, underscores, and hyphens."
GitHubURL:
Default: "https://github.com/owner/repository"
Description: "GitHub URL to be used as a resource tag value."
Type: String
AllowedPattern: "^https://github.com/[a-zA-Z0-9._-]+/[a-zA-Z0-9._-]+/?$"
ConstraintDescription: "The GitHub URL must start with 'https://github.com/' and can only contain alphanumeric characters, dots, underscores, and hyphens."
GitHubWFRunNumber:
Default: 1
Description: "The Workflow run number to be used as a resource tag value."
Type: Number
GitHubSHA:
Default: "d3b07384d113edec49eaa6238ad5ff00f6fb3796"
Description: "The sha value of the last commit to be used as a resource tag value."
Type: String
AllowedPattern: "^[a-fA-F0-9]{40}$"
ConstraintDescription: "The SHA value must be a 40-character hexadecimal string."
GitHubRepository:
Default: 0001-repo01name-py-cft
Description: "The GitHub Repository name to be used as a resource tag value."
Type: String
MinLength: 10
MaxLength: 30
AllowedPattern: "^\\d{4}-[a-z0-9]+(-[a-z]+)*$"
ConstraintDescription: "The repository length should be between 10 and 30, must contain only lowercase letters, numbers, dashes, dots, and should start with a letter."
CiBuild:
Default: ""
Description: "Ci Build of the feature branch to be appended to a resource name."
Type: String
###################################### CloudWtch Alarm ###########################################
ActionsEnabled:
Default: "true"
Description: "Enable Actions."
Type: String
AllowedValues: ["true", "false"]
ConstraintDescription: "The value must be either true or false."
SNSTopicBaseName:
Default: "sns-topic"
Description: "The SNS topic display name."
Type: String
MinLength: 3
MaxLength: 30
AllowedPattern: "^$|^[a-zA-Z0-9-]+$"
ConstraintDescription: "The length should be between 3 and 30, must contain only alphanumeric characters or dashes."
AlarmBaseName:
Default: "Alarm"
Description: "Base name of the CloudWatch Alarm."
Type: String
MinLength: 3
MaxLength: 30
AllowedPattern: "^[a-zA-Z0-9-]+$"
ConstraintDescription: "The length should be between 3 and 30, must contain only alphanumeric characters or dashes."
AlarmDescription:
Default: "Alarm Description"
Description: "Description of the CloudWatch Alarm."
Type: String
MinLength: 5
MaxLength: 100
AllowedPattern: "^$|^[a-zA-Z0-9- ]+$"
ConstraintDescription: "The length should be between 5 and 100, must contain only alphanumeric characters, spaces, or dashes."
ComparisonOperator:
Default: "GreaterThanThreshold"
Description: "Comparison Operator."
Type: String
AllowedValues: ["GreaterThanThreshold", "GreaterThanOrEqualToThreshold", "LessThanThreshold", "LessThanOrEqualToThreshold", "LessThanLowerOrGreaterThanUpperThreshold", "LessThanLowerThreshold", "GreaterThanUpperThreshold"]
ConstraintDescription: "The value must be one of the allowed values."
MetricName:
Default: "Metric"
Description: "Name of the CloudWatch Metric."
Type: String
MinLength: 3
MaxLength: 30
AllowedPattern: "^[a-zA-Z0-9-]+$"
ConstraintDescription: "The length should be between 3 and 30, must contain only alphanumeric characters or dashes."
MetricNamespace:
Default: "AWS/Glue"
Description: "Namespace of the CloudWatch Metric."
Type: String
MinLength: 5
MaxLength: 100
AllowedPattern: "^[a-zA-Z0-9/-]+$"
ConstraintDescription: "The length should be between 5 and 100, must contain only alphanumeric characters, slashes, or dashes."
AlarmPeriod:
Default: 300
Description: "Period of the CloudWatch Metric."
Type: Number
MinValue: 60
MaxValue: 86400
ConstraintDescription: "The value must be between 60 and 86400."
MetricStatistic:
Default: "Average"
Description: "Statistic of the CloudWatch Metric."
Type: String
AllowedValues: ["SampleCount", "Average", "Sum", "Minimum", "Maximum"]
ConstraintDescription: "The value must be one of the allowed values."
AlarmThreshold:
Default: 0
Description: "Threshold of the CloudWatch Metric."
Type: Number
MinValue: 0
ConstraintDescription: "The value must be greater than or equal to 0."
MetricUnit:
Default: "Count"
Description: "Unit of the CloudWatch Metric."
Type: String
AllowedValues: ["Count", "Seconds", "Microseconds", "Milliseconds", "None"]
ConstraintDescription: "The value must be one of the allowed values."
TreatMissingData:
Default: "missing"
Description: "Treat Missing Data."
Type: String
AllowedValues: ["missing", "ignore", "breaching", "notBreaching"]
ConstraintDescription: "The value must be one of the allowed values."
DatapointsToAlarm:
Default: 1
Description: "The number of datapoints to alarm."
Type: Number
MinValue: 1
ConstraintDescription: "The value must be greater than or equal to 1."
EvaluationPeriods:
Default: 1
Description: "The number of evaluation periods."
Type: Number
MinValue: 1
ConstraintDescription: "The value must be greater than or equal to 1."
DimensionName:
Default: "FunctionName"
Description: "The name of the dimension."
Type: String
MinLength: 3
MaxLength: 30
AllowedPattern: "^[a-zA-Z0-9-]+$"
ConstraintDescription: "The length should be between 3 and 30, must contain only alphanumeric characters or dashes."
DimensionValue:
Default: "arn:aws:lambda:us-east-1:111122223333:function:some-function-devl-us-east-1"
Description: "The value of the dimension."
Type: String
MinLength: 30
MaxLength: 255
AllowedPattern: "^[a-zA-Z0-9:/._-]+$"
ConstraintDescription: "The length should be between 50 and 255 characters, and must contain only alphanumeric characters, colons (:), slashes (/), dots (.), underscores (_), and hyphens (-)."
Conditions:
IsAlarmActionEnabled: !Equals [!Ref ActionsEnabled, "true"]
Resources:
###################################### CloudWatch Alarm ##########################################
CloudWatchAlarm:
Type: 'AWS::CloudWatch::Alarm'
Properties:
ActionsEnabled: !Ref ActionsEnabled
AlarmName: !Sub '${ProjectName}-${AlarmBaseName}-${Environment}-${AWS::Region}${CiBuild}'
AlarmDescription: !Ref AlarmDescription
AlarmActions: !If
- IsAlarmActionEnabled
-
- !Sub 'arn:${AWS::Partition}:sns:${AWS::Region}:${AWS::AccountId}:${ProjectName}-${SNSTopicBaseName}-${Environment}-${AWS::Region}${CiBuild}'
- !Ref "AWS::NoValue"
ComparisonOperator: !Ref ComparisonOperator
MetricName: !Ref MetricName
Namespace: !Ref MetricNamespace
Statistic: !Ref MetricStatistic
Threshold: !Ref AlarmThreshold
DatapointsToAlarm: !Ref DatapointsToAlarm #### Datapoints to alarm -> DatapointsToAlarm out of EvaluationPeriods
EvaluationPeriods: !Ref EvaluationPeriods
Dimensions:
- Name: !Ref DimensionName
Value: !Ref DimensionValue
Period: !Ref AlarmPeriod
TreatMissingData: !Ref TreatMissingData
Unit: !Ref MetricUnit
Tags:
- Key: "ProjectName"
Value: !Ref ProjectName
- Key: "Environment"
Value: !Ref Environment
- Key: "GitHubRef"
Value: !Ref GitHubRef
- Key: "GitHubURL"
Value: !Ref GitHubURL
- Key: "GitHubWFRunNumber"
Value: !Ref GitHubWFRunNumber
- Key: "GitHubSHA"
Value: !Ref GitHubSHA
- Key: "GitHubRepository"
Value: !Ref GitHubRepository
Outputs:
AlarmArn:
Description: The Arn of the CloudWatch Alarm.
Value: !GetAtt CloudWatchAlarm.Arn