-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate-alerting.yaml
89 lines (80 loc) · 3.38 KB
/
template-alerting.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
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
sam-eventbridge-alerting
SAM Template for Destination Account - Lambda Function Proc using Amazon EventBridge Cross-Account Event Bus / Event Bus Rules
# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
Globals:
Function:
Timeout: 3
Parameters:
SourceAccountId:
Type: String
Description: Source Account Id sending AWS Events
Default: 'SOURCEACCOUNTID'
Resources:
# Amazon EventBridge using Event Bus Rules
CloudWatchEventBus:
Type: AWS::Events::EventBus
Properties:
Name: "EventBus-for-CloudWatchEvents"
CustomEventBus:
Type: AWS::Events::EventBus
Properties:
Name: "EventBus-for-CustomEvents"
CloudWatchEventBusPolicy:
Type: AWS::Events::EventBusPolicy
Properties:
StatementId: !Sub "CloudWatchEventBusStatement-SourceAccount"
EventBusName: !Ref CloudWatchEventBus
Action: "events:PutEvents"
Principal: !Ref SourceAccountId
CustomEventBusPolicy:
Type: AWS::Events::EventBusPolicy
Properties:
StatementId: !Sub "CustomEventBusStatement-SourceAccount"
EventBusName: !Ref CustomEventBus
Action: "events:PutEvents"
Principal: !Ref SourceAccountId
EventBridgeAlertingFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
CodeUri: eventbridge/eventbridge_alerting
Handler: app.lambda_handler
Runtime: python3.8
Events:
CloudWatchAlarmEvent:
Type: CloudWatchEvent # More info about CloudWatchEvent Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#cloudwatchevent
Properties:
EventBusName: EventBus-for-CloudWatchEvents
Pattern:
source:
- aws.cloudwatch
detail-type:
- CloudWatch Alarm State Change
CustomEvent:
Type: CloudWatchEvent
Properties:
EventBusName: EventBus-for-CustomEvents
Pattern:
source:
- "customevent"
Outputs:
# ServerlessRestApi is an implicit API created out of Events key under Serverless::Function
# Find out more about other implicit resources you can reference within SAM
# https://github.com/awslabs/serverless-application-model/blob/master/docs/internals/generated_resources.rst#api
EventBridgeAlertingFunction:
Description: "EventBridge Alerting Lambda Function ARN"
Value: !GetAtt EventBridgeAlertingFunction.Arn
EventBridgeAlertingFunctionIamRole:
Description: "Implicit IAM Role created for EventBridge Alerting function"
Value: !GetAtt EventBridgeAlertingFunction.Arn
CloudWatchEventBusARN:
Description: CloudWatch Events (EventBridge) Event Bus ARN. Use this as Input when creating the corresponding AppAccount stack
Value: !GetAtt CloudWatchEventBus.Arn
CustomEventBusARN:
Description: CloudWatch Events (EventBridge) Event Bus ARN. Use this as Input when creating the corresponding AppAccount stack
Value: !GetAtt CustomEventBus.Arn
AllowedAWSAccountIDs:
Description: Source Account Id sending AWS Events
Value: !Ref SourceAccountId