This repository has been archived by the owner on Sep 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
/
marbot.yml
2138 lines (2138 loc) · 70 KB
/
marbot.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
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
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
# Copyright widdix GmbH
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
AWSTemplateFormatVersion: '2010-09-09'
Description: 'marbot.io: AWS basics monitoring (https://github.com/marbot-io/monitoring-jump-start)'
Metadata:
'AWS::CloudFormation::Interface':
ParameterGroups:
- Label:
default: 'marbot endpoint'
Parameters:
- EndpointId
- Stage
- Test
- Label:
default: 'Alerts'
Parameters:
- BudgetThreshold
- SavingsPlansCoverageThreshold
- SavingsPlansUtilizationThreshold
- TrustedAdvisor
- RootUserLogin
- CloudWatchAlarmFired
- CloudWatchAlarmOrphaned
- CloudWatchAlarmAutoClose
- BatchFailed
- CodePipelineFailed
- CodeBuildFailed
- CodeDeployFailed
- HealthIssue
- AutoScalingFailed
- GuardDutyFinding
- EMRFailed
- EBSFailed
- SSMFailed
- SSMAutomationFailed
- SSMConfigurationComplianceFailed
- SSMCommandFailed
- SSMStateManagerFailed
- RDSIssue
- GlueJobFailed
- EC2SpotInstanceInterruption
- ECSServiceFailed
- ECSDeploymentFailed
- ECSSpotInterruption
- MacieFinding
- SecurityHubFinding
- SecurityHubInsight
- OpsWorksDeploymentFailed
- OpsWorksCommandFailed
- OpsWorksInstanceFailed
- OpsWorksAlert
- ECRImageScanFinding
- DLMPolicyAlert
- IoTAnalyticsDatasetAlert
- ESSoftwareUpdateFailed
- XRayInsightUpdate
- BackupFailed
- AthenaFailed
- AppFlowFailed
- EC2FleetFailed
- ElasticBeanstalkFailed
- Inspector2Finding
- Label:
default: 'Notifications'
Parameters:
- CodePipelineNotifications
- CodeCommitPullRequestNotifications
- AMIUpdateNotificationECSOptimized
- AMIUpdateNotificationAmazonLinux
- AMIUpdateNotificationAmazonLinux2
- ACMCertificateApproachingExpiration
- ESSoftwareUpdateNotifications
- ApplicationAutoScalingNotifications
- BackupNotifications
- ECSDeploymentNotifications
Parameters:
EndpointId:
Description: 'Your marbot endpoint ID (to get this value: select a channel where marbot belongs to and send a message like this: "@marbot show me my endpoint id").'
Type: String
Stage:
Description: 'marbot stage (never change this!).'
Type: String
Default: v1
AllowedValues: [v1, dev]
Test:
Description: 'Send a single test alert.'
Type: String
Default: 'true'
AllowedValues: ['true', 'false']
BudgetThreshold:
Description: 'Receive an alert, if your monthly AWS costs (in USD) are higher than this value (works in us-east-1 only; set to -1 to disable).'
Type: Number
Default: -1
MinValue: -1
SavingsPlansCoverageThreshold:
Description: 'Receive an alert, if your monthly Savings Plans coverage (in percents) is lower than this value (works in us-east-1 only; set to -1 to disable).'
Type: Number
Default: -1
MinValue: -1
MaxValue: 100
SavingsPlansUtilizationThreshold:
Description: 'Receive an alert, if your monthly Savings Plans utilization (in percents) is lower than this value (works in us-east-1 only; set to -1 to disable).'
Type: Number
Default: -1
MinValue: -1
MaxValue: 100
AMIUpdateNotificationECSOptimized:
Description: 'Receive a notification, if a new ECS optimized AMI is released (works in us-east-1 only).'
Type: String
Default: false
AllowedValues: [true, false]
AMIUpdateNotificationAmazonLinux:
Description: 'Receive a notification, if a new Amazon Linux AMI is released (works in us-east-1 only).'
Type: String
Default: false
AllowedValues: [true, false]
AMIUpdateNotificationAmazonLinux2:
Description: 'Receive a notification, if a new Amazon Linux 2 AMI is released (works in us-east-1 only).'
Type: String
Default: true
AllowedValues: [true, false]
RootUserLogin:
Description: 'Receive an alert, if a root user login is performed.'
Type: String
Default: true
AllowedValues: [true, false]
CloudWatchAlarmFired:
Description: 'Receive an alert, if any CloudWatch Alarm fires (state ALARM; instead of defining actions for each alarm).'
Type: String
Default: true
AllowedValues: [true, false]
CloudWatchAlarmOrphaned:
Description: 'Receive an alert, if any CloudWatch Alarm does not receive any data (state INSUFFICIENT_DATA; instead of defining actions for each alarm).'
Type: String
Default: false
AllowedValues: [true, false]
CloudWatchAlarmAutoClose:
Description: 'Auto-Close an alert, if any CloudWatch Alarm fires (state OK; instead of defining actions for each alarm).'
Type: String
Default: false
AllowedValues: [true, false]
BatchFailed:
Description: 'Receive an alert, if any Batch job fails.'
Type: String
Default: true
AllowedValues: [true, false]
CodePipelineFailed:
Description: 'Receive an alert, if any CodePipeline execution fails.'
Type: String
Default: true
AllowedValues: [true, false]
CodePipelineNotifications:
Description: 'Receive a notification, if a CodePipeline pipeline succeedes.'
Type: String
Default: true
AllowedValues: [true, false]
CodeCommitPullRequestNotifications:
Description: 'Receive a notification, if a CodeCommit pull request changes.'
Type: String
Default: true
AllowedValues: [true, false]
CodeBuildFailed:
Description: 'Receive an alert, if any CodeBuild build fails.'
Type: String
Default: true
AllowedValues: [true, false]
CodeDeployFailed:
Description: 'Receive an alert, if any CodeDeploy deployment fails.'
Type: String
Default: true
AllowedValues: [true, false]
HealthIssue:
Description: 'Receive an alert, if AWS is experiencing events that may impact you.'
Type: String
Default: true
AllowedValues: [true, false]
TrustedAdvisor:
Description: 'Receive an alert, if any Trusted Advisor check turns red (works in us-east-1 only, requires AWS Business Support or higher).'
Type: String
Default: true
AllowedValues: [true, false]
AutoScalingFailed:
Description: 'Receive an alert, if any EC2 instance fails to start or terminate in an Auto Scaling Group.'
Type: String
Default: true
AllowedValues: [true, false]
GuardDutyFinding:
Description: 'Receive an alert, if a GuardDuty finding is created.'
Type: String
Default: true
AllowedValues: [true, false]
EMRFailed:
Description: 'Receive an alert, if any EMR step or auto scaling policy fails.'
Type: String
Default: true
AllowedValues: [true, false]
EBSFailed:
Description: 'Receive an alert, if any EBS snapshot fails.'
Type: String
Default: true
AllowedValues: [true, false]
SSMFailed: # should be called SSMMaintenanceWindowFailed, but was not changed for backward compatibility
Description: 'Receive an alert, if any SSM Maintenance Window execution fails.'
Type: String
Default: true
AllowedValues: [true, false]
SSMAutomationFailed:
Description: 'Receive an alert, if any SSM Automation execution fails.'
Type: String
Default: true
AllowedValues: [true, false]
SSMConfigurationComplianceFailed:
Description: 'Receive an alert, if any SSM Configuration Compliance check fails.'
Type: String
Default: true
AllowedValues: [true, false]
SSMCommandFailed:
Description: 'Receive an alert, if any SSM Command execution fails.'
Type: String
Default: true
AllowedValues: [true, false]
SSMStateManagerFailed:
Description: 'Receive an alert, if any SSM State Manager association fails.'
Type: String
Default: true
AllowedValues: [true, false]
RDSIssue:
Description: 'Receive an alert, if any RDS issue is detected.'
Type: String
Default: true
AllowedValues: [true, false]
GlueJobFailed:
Description: 'Receive an alert, if any Glue job fails.'
Type: String
Default: true
AllowedValues: [true, false]
EC2SpotInstanceInterruption:
Description: 'Receive a notification, if any EC2 Spot instance is interrupted.'
Type: String
Default: true
AllowedValues: [true, false]
ECSServiceFailed:
Description: 'Receive an alert, if any ECS service fails.'
Type: String
Default: true
AllowedValues: [true, false]
ECSDeploymentFailed:
Description: 'Receive an alert, if any ECS deployment fails.'
Type: String
Default: true
AllowedValues: [true, false]
ECSSpotInterruption:
Description: 'Receive an alert, if an ECS Fargate Spot task gets interrupted or fails to launch.'
Type: String
Default: true
AllowedValues: [true, false]
MacieFinding:
Description: 'Receive an alert, if Macie generates a new finding.'
Type: String
Default: true
AllowedValues: [true, false]
SecurityHubFinding:
Description: 'Receive an alert, if a SecurityHub finding is created.'
Type: String
Default: true
AllowedValues: [true, false]
SecurityHubInsight:
Description: 'Receive an alert, if a SecurityHub insight is created.'
Type: String
Default: true
AllowedValues: [true, false]
OpsWorksDeploymentFailed:
Description: 'Receive an alert, if an OpsWorks deployment fails.'
Type: String
Default: true
AllowedValues: [true, false]
OpsWorksCommandFailed:
Description: 'Receive an alert, if an OpsWorks command fails.'
Type: String
Default: true
AllowedValues: [true, false]
OpsWorksInstanceFailed:
Description: 'Receive an alert, if an OpsWorks instance fails.'
Type: String
Default: true
AllowedValues: [true, false]
OpsWorksAlert:
Description: 'Receive an alert, if OpsWorks fires an alert.'
Type: String
Default: true
AllowedValues: [true, false]
ECRImageScanFinding:
Description: 'Receive an alert, if a ECR Image Scan finding of severity MEDIUM, HIGH, or CRITICAL is created.'
Type: String
Default: true
AllowedValues: [true, false]
DLMPolicyAlert:
Description: 'Receive an alert, if a DLM policy fires an alert.'
Type: String
Default: true
AllowedValues: [true, false]
IoTAnalyticsDatasetAlert:
Description: 'Receive an alert, if an IoT Analytics dataset fires an alert.'
Type: String
Default: true
AllowedValues: [true, false]
ACMCertificateApproachingExpiration:
Description: 'Receive a notification, if an ACM certificate approaches expiration.'
Type: String
Default: true
AllowedValues: [true, false]
ESSoftwareUpdateFailed:
Description: 'Receive an alert, if an Elasticsearch/OpenSearch software update fails.'
Type: String
Default: true
AllowedValues: [true, false]
ESSoftwareUpdateNotifications:
Description: 'Receive notifications about Elasticsearch/OpenSearch software updates.'
Type: String
Default: true
AllowedValues: [true, false]
ApplicationAutoScalingNotifications:
Description: 'Receive notifications about Application Auto Scaling Scaling Activities.'
Type: String
Default: true
AllowedValues: [true, false]
XRayInsightUpdate:
Description: 'Receive an alert, if X-Ray Insight detects a fault.'
Type: String
Default: true
AllowedValues: [true, false]
BackupFailed:
Description: 'Receive an alert, if AWS Backup fails.'
Type: String
Default: true
AllowedValues: [true, false]
BackupNotifications:
Description: 'Receive notifications about AWS Backup activities.'
Type: String
Default: true
AllowedValues: [true, false]
AthenaFailed:
Description: 'Receive an alert, if Athena fails.'
Type: String
Default: true
AllowedValues: [true, false]
AppFlowFailed:
Description: 'Receive an alert, if AppFlow fails.'
Type: String
Default: true
AllowedValues: [true, false]
EC2FleetFailed:
Description: 'Receive an alert, if EC2 (Spot) Fleet fails.'
Type: String
Default: true
AllowedValues: [true, false]
ECSDeploymentNotifications:
Description: 'Receive notifications when AWS deployments succeed.'
Type: String
Default: true
AllowedValues: [true, false]
ElasticBeanstalkFailed:
Description: 'Receive an alert, if Elastic Beanstalk fails.'
Type: String
Default: true
AllowedValues: [true, false]
Inspector2Finding:
Description: 'Receive an alert, if an Inspector2 finding is created.'
Type: String
Default: true
AllowedValues: [true, false]
Conditions:
NorthVirginia: !Equals [!Ref 'AWS::Region', 'us-east-1']
TestEnabled: !Equals [!Ref Test, 'true']
# Only available in us-east-1
BudgetEnabled: !And [!Condition NorthVirginia, !Not [!Equals [!Ref BudgetThreshold, '-1']]]
SavingsPlansCoverageEnabled: !And [!Condition NorthVirginia, !Not [!Equals [!Ref SavingsPlansCoverageThreshold, '-1']]]
SavingsPlansUtilizationEnabled: !And [!Condition NorthVirginia, !Not [!Equals [!Ref SavingsPlansUtilizationThreshold, '-1']]]
AMIUpdateNotificationECSOptimizedEnabled: !And [!Condition NorthVirginia, !Equals [!Ref AMIUpdateNotificationECSOptimized, 'true']]
AMIUpdateNotificationAmazonLinuxEnabled: !And [!Condition NorthVirginia, !Equals [!Ref AMIUpdateNotificationAmazonLinux, 'true']]
AMIUpdateNotificationAmazonLinux2Enabled: !And [!Condition NorthVirginia, !Equals [!Ref AMIUpdateNotificationAmazonLinux2, 'true']]
TrustedAdvisorEnabled: !And [!Condition NorthVirginia, !Equals [!Ref TrustedAdvisor, 'true']]
# Needs to be created in each region
RootUserLoginEnabled: !Equals [!Ref RootUserLogin, 'true']
CloudWatchAlarmFiredEnabled: !Equals [!Ref CloudWatchAlarmFired, 'true']
CloudWatchAlarmOrphanedEnabled: !Equals [!Ref CloudWatchAlarmOrphaned, 'true']
CloudWatchAlarmAutoCloseEnabled: !Equals [!Ref CloudWatchAlarmAutoClose, 'true']
CloudWatchAlarmEnabled: !Or [!Condition CloudWatchAlarmFiredEnabled, !Condition CloudWatchAlarmOrphanedEnabled, !Condition CloudWatchAlarmAutoCloseEnabled]
BatchFailedEnabled: !Equals [!Ref BatchFailed, 'true']
CodePipelineFailedEnabled: !Equals [!Ref CodePipelineFailed, 'true']
CodePipelineNotificationsEnabled: !Equals [!Ref CodePipelineNotifications, 'true']
CodePipelineNotificationsDisabled: !Not [!Condition CodePipelineNotificationsEnabled]
CodeCommitPullRequestNotificationsEnabled: !Equals [!Ref CodeCommitPullRequestNotifications, 'true']
CodeBuildFailedEnabled: !Equals [!Ref CodeBuildFailed, 'true']
CodeBuildFailedEnabledAndCodePipelineFailedEnabled: !And [!Condition CodeBuildFailedEnabled, !Condition CodePipelineNotificationsEnabled]
CodeBuildFailedEnabledAndCodePipelineFailedDisabled: !And [!Condition CodeBuildFailedEnabled, !Condition CodePipelineNotificationsDisabled]
CodeDeployFailedEnabled: !Equals [!Ref CodeDeployFailed, 'true']
HealthIssueEnabled: !Equals [!Ref HealthIssue, 'true']
AutoScalingFailedEnabled: !Equals [!Ref AutoScalingFailed, 'true']
GuardDutyFindingEnabled: !Equals [!Ref GuardDutyFinding, 'true']
EMRFailedEnabled: !Equals [!Ref EMRFailed, 'true']
EBSFailedEnabled: !Equals [!Ref EBSFailed, 'true']
SSMFailedEnabled: !Equals [!Ref SSMFailed, 'true'] # should be called SSMMaintenanceWindowFailedEnabled, but was not changed for backward compatibility
SSMAutomationFailedEnabled: !Equals [!Ref SSMAutomationFailed, 'true']
SSMConfigurationComplianceFailedEnabled: !Equals [!Ref SSMConfigurationComplianceFailed, 'true']
SSMCommandFailedEnabled: !Equals [!Ref SSMCommandFailed, 'true']
SSMStateManagerFailedEnabled: !Equals [!Ref SSMStateManagerFailed, 'true']
RDSIssueEnabled: !Equals [!Ref RDSIssue, 'true']
GlueJobFailedEnabled: !Equals [!Ref GlueJobFailed, 'true']
EC2SpotInstanceInterruptionEnabled: !Equals [!Ref EC2SpotInstanceInterruption, 'true']
ECSServiceFailedEnabled: !Equals [!Ref ECSServiceFailed, 'true']
ECSDeploymentFailedEnabled: !Equals [!Ref ECSDeploymentFailed, 'true']
ECSSpotInterruptionEnabled: !Equals [!Ref ECSSpotInterruption, 'true']
MacieFindingEnabled: !Equals [!Ref MacieFinding, 'true']
SecurityHubFindingEnabled: !Equals [!Ref SecurityHubFinding, 'true']
SecurityHubInsightEnabled: !Equals [!Ref SecurityHubInsight, 'true']
OpsWorksDeploymentFailedEnabled: !Equals [!Ref OpsWorksDeploymentFailed, 'true']
OpsWorksCommandFailedEnabled: !Equals [!Ref OpsWorksCommandFailed, 'true']
OpsWorksInstanceFailedEnabled: !Equals [!Ref OpsWorksInstanceFailed, 'true']
OpsWorksAlertEnabled: !Equals [!Ref OpsWorksAlert, 'true']
ECRImageScanFindingEnabled: !Equals [!Ref ECRImageScanFinding, 'true']
DLMPolicyAlertEnabled: !Equals [!Ref DLMPolicyAlert, 'true']
IoTAnalyticsDatasetAlertEnabled: !Equals [!Ref IoTAnalyticsDatasetAlert, 'true']
ACMCertificateApproachingExpirationEnabled: !Equals [!Ref ACMCertificateApproachingExpiration, 'true']
ESSoftwareUpdateFailedEnabled: !Equals [!Ref ESSoftwareUpdateFailed, 'true']
ESSoftwareUpdateNotificationsEnabled: !Equals [!Ref ESSoftwareUpdateNotifications, 'true']
ApplicationAutoScalingNotificationsEnabled: !Equals [!Ref ApplicationAutoScalingNotifications, 'true']
XRayInsightUpdateEnabled: !Equals [!Ref XRayInsightUpdate, 'true']
BackupFailedEnabled: !Equals [!Ref BackupFailed, 'true']
BackupNotificationsEnabled: !Equals [!Ref BackupNotifications, 'true']
AthenaFailedEnabled: !Equals [!Ref AthenaFailed, 'true']
AppFlowFailedEnabled: !Equals [!Ref AppFlowFailed, 'true']
EC2FleetFailedEnabled: !Equals [!Ref EC2FleetFailed, 'true']
ECSDeploymentNotificationsEnabled: !Equals [!Ref ECSDeploymentNotifications, 'true']
ElasticBeanstalkFailedEnabled: !Equals [!Ref ElasticBeanstalkFailed, 'true']
Inspector2FindingEnabled: !Equals [!Ref Inspector2Finding, 'true']
Resources:
##########################################################################
# #
# TOPIC #
# #
##########################################################################
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:
Service:
- 'events.amazonaws.com' # Allow EventBridge
- 'budgets.amazonaws.com' # Allow Budget Notifications
- 'rds.amazonaws.com' # Allow RDS Events
- 's3.amazonaws.com' # Allow S3 Event Notifications
- 'backup.amazonaws.com' # Allow Backup Events
- 'codestar-notifications.amazonaws.com' # Allow CodeStar Notifications
- 'devops-guru.amazonaws.com' # Allow DevOps Guru Notifications
Action: 'sns:Publish'
Resource: !Ref Topic
- Sid: Sid2
Effect: Allow
Principal:
AWS: '*' # Allow CloudWatch Alarms, ElastiCache Notifications, Elastic Beanstalk Notifications, Auto Scaling Notification
Action: 'sns:Publish'
Resource: !Ref Topic
Condition:
StringEquals:
'AWS:SourceOwner': !Ref 'AWS::AccountId'
- Sid: Sid3
Effect: Allow
Principal:
Service: 'ses.amazonaws.com' # Allow SES Notifications & Events
Action: 'sns:Publish'
Resource: !Ref Topic
Condition:
StringEquals:
'AWS:Referer': !Ref 'AWS::AccountId'
Topics:
- !Ref Topic
TopicEndpointSubscription:
DependsOn: TopicPolicy
Type: 'AWS::SNS::Subscription'
Properties:
DeliveryPolicy:
healthyRetryPolicy:
minDelayTarget: 1
maxDelayTarget: 60
numRetries: 100
numNoDelayRetries: 0
backoffFunction: exponential
throttlePolicy:
maxReceivesPerSecond: 1
Endpoint: !Sub 'https://api.marbot.io/${Stage}/endpoint/${EndpointId}'
Protocol: https
TopicArn: !Ref Topic
MonitoringJumpStartEvent:
DependsOn: TopicEndpointSubscription
Type: 'AWS::Events::Rule'
Properties:
Description: 'Monitoring Jump Start connection. (created by marbot)'
ScheduleExpression: 'rate(30 days)'
State: ENABLED
Targets:
- Arn: !Ref Topic
Id: marbot
Input: !Sub |
{
"Type": "monitoring-jump-start-connection",
"StackTemplate": "marbot",
"StackVersion": "3.3.0",
"Partition": "${AWS::Partition}",
"AccountId": "${AWS::AccountId}",
"Region": "${AWS::Region}",
"StackId": "${AWS::StackId}",
"StackName": "${AWS::StackName}"
}
##########################################################################
# #
# ALARMS #
# #
##########################################################################
TrustedAdvisorCostOptimizationAlarm:
Condition: TrustedAdvisorEnabled
DependsOn: TopicEndpointSubscription
Type: 'AWS::CloudWatch::Alarm'
Properties:
AlarmActions:
- !Ref Topic
AlarmDescription: 'Trusted Advisor Cost Optimization checks are red. (created by marbot)'
ComparisonOperator: GreaterThanThreshold
Dimensions:
- Name: Category
Value: 'Cost Optimization'
EvaluationPeriods: 1
MetricName: RedChecks
Namespace: 'AWS/TrustedAdvisor'
OKActions:
- !Ref Topic
Period: 21600
Statistic: Maximum
Threshold: 0
TrustedAdvisorFaultToleranceAlarm:
Condition: TrustedAdvisorEnabled
DependsOn: TopicEndpointSubscription
Type: 'AWS::CloudWatch::Alarm'
Properties:
AlarmActions:
- !Ref Topic
AlarmDescription: 'Trusted Advisor Fault Tolerance checks are red. (created by marbot)'
ComparisonOperator: GreaterThanThreshold
Dimensions:
- Name: Category
Value: 'Fault Tolerance'
EvaluationPeriods: 1
MetricName: RedChecks
Namespace: 'AWS/TrustedAdvisor'
OKActions:
- !Ref Topic
Period: 21600
Statistic: Maximum
Threshold: 0
TrustedAdvisorPerformanceAlarm:
Condition: TrustedAdvisorEnabled
DependsOn: TopicEndpointSubscription
Type: 'AWS::CloudWatch::Alarm'
Properties:
AlarmActions:
- !Ref Topic
AlarmDescription: 'Trusted Advisor Performance checks are red. (created by marbot)'
ComparisonOperator: GreaterThanThreshold
Dimensions:
- Name: Category
Value: 'Performance'
EvaluationPeriods: 1
MetricName: RedChecks
Namespace: 'AWS/TrustedAdvisor'
OKActions:
- !Ref Topic
Period: 21600
Statistic: Maximum
Threshold: 0
TrustedAdvisorSecurityAlarm:
Condition: TrustedAdvisorEnabled
DependsOn: TopicEndpointSubscription
Type: 'AWS::CloudWatch::Alarm'
Properties:
AlarmActions:
- !Ref Topic
AlarmDescription: 'Trusted Advisor Security checks are red. (created by marbot)'
ComparisonOperator: GreaterThanThreshold
Dimensions:
- Name: Category
Value: 'Security'
EvaluationPeriods: 1
MetricName: RedChecks
Namespace: 'AWS/TrustedAdvisor'
OKActions:
- !Ref Topic
Period: 21600
Statistic: Maximum
Threshold: 0
TrustedAdvisorServiceLimitsAlarm:
Condition: TrustedAdvisorEnabled
DependsOn: TopicEndpointSubscription
Type: 'AWS::CloudWatch::Alarm'
Properties:
AlarmActions:
- !Ref Topic
AlarmDescription: 'Trusted Advisor Service Limits checks are red. (created by marbot)'
ComparisonOperator: GreaterThanThreshold
Dimensions:
- Name: Category
Value: 'Service Limits'
EvaluationPeriods: 1
MetricName: RedChecks
Namespace: 'AWS/TrustedAdvisor'
OKActions:
- !Ref Topic
Period: 21600
Statistic: Maximum
Threshold: 0
##########################################################################
# #
# SUBSCRIPTIONS #
# #
##########################################################################
AMIUpdateNotificationECSOptimizedSubscription:
Condition: AMIUpdateNotificationECSOptimizedEnabled
DependsOn: TopicEndpointSubscription
Type: 'AWS::SNS::Subscription'
Properties:
DeliveryPolicy:
healthyRetryPolicy:
minDelayTarget: 1
maxDelayTarget: 60
numRetries: 100
numNoDelayRetries: 0
backoffFunction: exponential
throttlePolicy:
maxReceivesPerSecond: 1
Endpoint: !Sub 'https://api.marbot.io/${Stage}/endpoint/${EndpointId}'
Protocol: https
TopicArn: 'arn:aws:sns:us-east-1:177427601217:ecs-optimized-amazon-ami-update'
AMIUpdateNotificationAmazonLinuxSubscription:
Condition: AMIUpdateNotificationAmazonLinuxEnabled
DependsOn: TopicEndpointSubscription
Type: 'AWS::SNS::Subscription'
Properties:
DeliveryPolicy:
healthyRetryPolicy:
minDelayTarget: 1
maxDelayTarget: 60
numRetries: 100
numNoDelayRetries: 0
backoffFunction: exponential
throttlePolicy:
maxReceivesPerSecond: 1
Endpoint: !Sub 'https://api.marbot.io/${Stage}/endpoint/${EndpointId}'
Protocol: https
TopicArn: 'arn:aws:sns:us-east-1:137112412989:amazon-linux-ami-updates'
AMIUpdateNotificationAmazonLinux2Subscription:
Condition: AMIUpdateNotificationAmazonLinux2Enabled
DependsOn: TopicEndpointSubscription
Type: 'AWS::SNS::Subscription'
Properties:
DeliveryPolicy:
healthyRetryPolicy:
minDelayTarget: 1
maxDelayTarget: 60
numRetries: 100
numNoDelayRetries: 0
backoffFunction: exponential
throttlePolicy:
maxReceivesPerSecond: 1
Endpoint: !Sub 'https://api.marbot.io/${Stage}/endpoint/${EndpointId}'
Protocol: https
TopicArn: 'arn:aws:sns:us-east-1:137112412989:amazon-linux-2-ami-updates'
##########################################################################
# #
# BUDGET #
# #
##########################################################################
Budget:
Condition: BudgetEnabled
DependsOn: TopicEndpointSubscription
Type: 'AWS::Budgets::Budget'
Properties:
NotificationsWithSubscribers:
- Subscribers:
- SubscriptionType: SNS
Address: !Ref Topic
Notification:
ComparisonOperator: 'GREATER_THAN'
NotificationType: ACTUAL
Threshold: 100
ThresholdType: PERCENTAGE
- Subscribers:
- SubscriptionType: SNS
Address: !Ref Topic
Notification:
ComparisonOperator: 'GREATER_THAN'
NotificationType: FORECASTED
Threshold: 100
ThresholdType: PERCENTAGE
Budget:
BudgetLimit:
Amount: !Ref BudgetThreshold
Unit: USD
TimeUnit: MONTHLY
CostTypes:
IncludeSupport: false
IncludeOtherSubscription: false
IncludeTax: false
IncludeSubscription: true
IncludeUpfront: false
IncludeDiscount: true
IncludeCredit: false
IncludeRecurring: false
UseAmortized: false
IncludeRefund: false
UseBlended: false
BudgetType: COST
SavingsPlansCoverage:
Condition: SavingsPlansCoverageEnabled
DependsOn: TopicEndpointSubscription
Type: 'AWS::Budgets::Budget'
Properties:
NotificationsWithSubscribers:
- Subscribers:
- SubscriptionType: SNS
Address: !Ref Topic
Notification:
ComparisonOperator: 'LESS_THAN'
NotificationType: ACTUAL
Threshold: !Ref SavingsPlansCoverageThreshold
ThresholdType: PERCENTAGE
Budget:
TimeUnit: MONTHLY
BudgetType: SAVINGS_PLANS_COVERAGE
SavingsPlansUtilization:
Condition: SavingsPlansUtilizationEnabled
DependsOn: TopicEndpointSubscription
Type: 'AWS::Budgets::Budget'
Properties:
NotificationsWithSubscribers:
- Subscribers:
- SubscriptionType: SNS
Address: !Ref Topic
Notification:
ComparisonOperator: 'LESS_THAN'
NotificationType: ACTUAL
Threshold: !Ref SavingsPlansUtilizationThreshold
ThresholdType: PERCENTAGE
Budget:
TimeUnit: MONTHLY
BudgetType: SAVINGS_PLANS_UTILIZATION
##########################################################################
# #
# EVENTS #
# #
##########################################################################
RootUserLoginEvent:
Condition: RootUserLoginEnabled
DependsOn: TopicEndpointSubscription
Type: 'AWS::Events::Rule'
Properties:
Description: 'A root user login was detected, better use IAM users instead. (created by marbot)'
EventPattern:
'detail-type':
- 'AWS Console Sign In via CloudTrail'
detail:
userIdentity:
arn:
- !Sub 'arn:aws:iam::${AWS::AccountId}:root'
State: ENABLED
Targets:
- Arn: !Ref Topic
Id: marbot
CloudWatchAlarmFilterRole:
Condition: CloudWatchAlarmEnabled
Type: 'AWS::IAM::Role'
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service: 'lambda.amazonaws.com'
Action: 'sts:AssumeRole'
Policies:
- PolicyName: filter
PolicyDocument:
Statement:
- Effect: Allow
Action: 'cloudwatch:describeAlarms'
Resource: '*'
- Effect: Allow
Action: 'sns:Publish'
Resource: !Ref Topic
CloudWatchAlarmFilterPolicy:
Condition: CloudWatchAlarmEnabled
Type: 'AWS::IAM::Policy'
Properties:
PolicyDocument:
Statement:
- Effect: Allow
Action:
- 'logs:CreateLogStream'
- 'logs:PutLogEvents'
Resource: !GetAtt 'CloudWatchAlarmFilterLogGroup.Arn'
PolicyName: lambda
Roles:
- !Ref CloudWatchAlarmFilterRole
CloudWatchAlarmFilterFunction: # Filter out alarms to trigger autoscaling actions
Condition: CloudWatchAlarmEnabled
DependsOn: TopicEndpointSubscription
Type: 'AWS::Lambda::Function'
Properties:
Handler: 'index.handler'
Runtime: 'nodejs18.x'
MemorySize: 1024
Timeout: 30
Role: !GetAtt 'CloudWatchAlarmFilterRole.Arn'
Environment:
Variables:
TOPIC_ARN: !Ref Topic
Code:
ZipFile: |
'use strict';
const { CloudWatchClient, DescribeAlarmsCommand } = require('@aws-sdk/client-cloudwatch');
const cloudwatch = new CloudWatchClient({apiVersion: '2010-08-01'});
const { SNSClient, PublishCommand } = require('@aws-sdk/client-sns');
const sns = new SNSClient({apiVersion: '2010-03-31'});
const STATE2ACTION = {
'ALARM': 'AlarmActions',
'OK': 'OKActions',
'INSUFFICIENT_DATA': 'InsufficientDataActions'
};
exports.handler = async (event) => {
console.log(JSON.stringify(event));
const data = await cloudwatch.send(new DescribeAlarmsCommand({
AlarmNames: [event.detail.alarmName],
MaxRecords: 1
}));
const alarms = [...data.CompositeAlarms, ...data.MetricAlarms];
console.log(JSON.stringify(alarms));
if (alarms.length === 0) {
return;
} else {
const alarm = alarms[0];
const action = STATE2ACTION[event.detail.state.value];
const actions = alarm[action];
console.log(JSON.stringify(actions));
if (alarm.ActionsEnabled) {
if (actions.filter(action => action.includes(':autoscaling:')).length > 0) {
console.log("drop");
} else {
console.log("publish");
await sns.send(new PublishCommand({
TopicArn: process.env.TOPIC_ARN,
Message: JSON.stringify(event)
}));
}
}
}
};
CloudWatchAlarmFilterAlarmErrorsTooHigh:
Condition: CloudWatchAlarmEnabled
DependsOn: TopicEndpointSubscription
Type: 'AWS::CloudWatch::Alarm'
Properties:
AlarmDescription: 'Invocations failed due to errors in the function'
Namespace: 'AWS/Lambda'
MetricName: Errors
Statistic: Sum
Period: 60
EvaluationPeriods: 1
ComparisonOperator: GreaterThanThreshold
Threshold: 0
TreatMissingData: notBreaching
AlarmActions:
- !Ref Topic
Dimensions:
- Name: FunctionName
Value: !Ref CloudWatchAlarmFilterFunction
CloudWatchAlarmFilterAlarmThrottlesTooHigh:
Condition: CloudWatchAlarmEnabled
DependsOn: TopicEndpointSubscription
Type: 'AWS::CloudWatch::Alarm'
Properties:
AlarmDescription: 'Invocation attempts that were throttled due to invocation rates exceeding the concurrent limits'
Namespace: 'AWS/Lambda'
MetricName: Throttles
Statistic: Sum
Period: 60
EvaluationPeriods: 1
ComparisonOperator: GreaterThanThreshold
Threshold: 0
TreatMissingData: notBreaching
AlarmActions:
- !Ref Topic
Dimensions:
- Name: FunctionName
Value: !Ref CloudWatchAlarmFilterFunction
CloudWatchAlarmFilterLogGroup:
Condition: CloudWatchAlarmEnabled
Type: 'AWS::Logs::LogGroup'
Properties:
LogGroupName: !Sub '/aws/lambda/${CloudWatchAlarmFilterFunction}'
RetentionInDays: 14
CloudWatchAlarmFilterPermissionFiredEvent:
Condition: CloudWatchAlarmFiredEnabled
Type: 'AWS::Lambda::Permission'
Properties:
Action: 'lambda:InvokeFunction'
FunctionName: !Ref CloudWatchAlarmFilterFunction
Principal: 'events.amazonaws.com'
SourceArn: !GetAtt 'CloudWatchAlarmFiredEvent.Arn'
CloudWatchAlarmFilterPermissionAlarmAutoCloseEvent:
Condition: CloudWatchAlarmAutoCloseEnabled
Type: 'AWS::Lambda::Permission'
Properties:
Action: 'lambda:InvokeFunction'
FunctionName: !Ref CloudWatchAlarmFilterFunction
Principal: 'events.amazonaws.com'
SourceArn: !GetAtt 'CloudWatchAlarmAutoCloseEvent.Arn'
CloudWatchAlarmFilterPermissionOrphanedEvent:
Condition: CloudWatchAlarmOrphanedEnabled
Type: 'AWS::Lambda::Permission'
Properties:
Action: 'lambda:InvokeFunction'
FunctionName: !Ref CloudWatchAlarmFilterFunction
Principal: 'events.amazonaws.com'
SourceArn: !GetAtt 'CloudWatchAlarmOrphanedEvent.Arn'
CloudWatchAlarmFiredEvent:
Condition: CloudWatchAlarmFiredEnabled
DependsOn: CloudWatchAlarmFilterPolicy
Type: 'AWS::Events::Rule'
Properties:
Description: 'A CloudWatch Alarm fired. (created by marbot)'
EventPattern:
source:
- 'aws.cloudwatch'
'detail-type':
- 'CloudWatch Alarm State Change'
detail:
state:
value:
- ALARM
State: ENABLED
Targets:
- Arn: !GetAtt 'CloudWatchAlarmFilterFunction.Arn'
Id: marbot
CloudWatchAlarmOrphanedEvent:
Condition: CloudWatchAlarmOrphanedEnabled
DependsOn: TopicEndpointSubscription
Type: 'AWS::Events::Rule'
Properties:
Description: 'A CloudWatch Alarm orphaned. (created by marbot)'
EventPattern:
source:
- 'aws.cloudwatch'
'detail-type':
- 'CloudWatch Alarm State Change'
detail:
state:
value:
- INSUFFICIENT_DATA
State: ENABLED
Targets:
- Arn: !GetAtt 'CloudWatchAlarmFilterFunction.Arn'
Id: marbot
CloudWatchAlarmAutoCloseEvent:
Condition: CloudWatchAlarmAutoCloseEnabled
DependsOn: TopicEndpointSubscription
Type: 'AWS::Events::Rule'
Properties:
Description: 'A CloudWatch Alarm could be auto-closed. (created by marbot)'
EventPattern:
source:
- 'aws.cloudwatch'
'detail-type':