-
Notifications
You must be signed in to change notification settings - Fork 0
/
cfn.yaml
95 lines (91 loc) · 2.38 KB
/
cfn.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
AWSTemplateFormatVersion: "2010-09-09"
Description: "Api Gateway Monitoring Automation"
Parameters:
AlarmEmail:
Default: "jane.doe@example.com"
Description: "Email address to notify of operational issues"
Type: "String"
Resources:
EventRule:
Type: AWS::Events::Rule
Properties:
Description: "EventRule"
EventPattern:
source:
- aws.apigateway
detail-type:
- AWS API Call via CloudTrail
detail:
eventSource:
- apigateway.amazonaws.com
eventName:
- CreateDeployment
Targets:
-
Arn:
Fn::GetAtt:
- "LambdaFunction"
- "Arn"
Id: "TargetFunctionV1"
PermissionsForEventsToInvokeLambda:
Type: AWS::Lambda::Permission
Properties:
FunctionName:
Ref: "LambdaFunction"
Action: "lambda:InvokeFunction"
Principal: "events.amazonaws.com"
SourceArn:
Fn::GetAtt:
- "EventRule"
- "Arn"
LambdaFunction:
Type: "AWS::Lambda::Function"
Properties:
Code:
Description: "My Function"
FunctionName: "apigateway-monitoring"
Handler: "create-alarms.handler"
MemorySize: 128
Role: !GetAtt "LambdaRole.Arn"
Runtime: "python3.7"
Timeout: 10
Environment:
Variables:
API_GAWATE_ENDPOINT: "somerandomsstuff"
ALARM_SNS_TOPIC: !Ref "AlarmSNSTopic"
LambdaRole:
Type: "AWS::IAM::Role"
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Action:
- "sts:AssumeRole"
Effect: "Allow"
Principal:
Service:
- "lambda.amazonaws.com"
Policies:
- PolicyDocument:
Version: "2012-10-17"
Statement:
- Action:
- "logs:*"
- "lambda:*"
- "events:*"
- "apigateway:*"
- "sns:*"
- "cloudwatch:*"
Effect: "Allow"
Resource: "*"
PolicyName: "lambda"
AlarmSNSTopic:
Type: AWS::SNS::Topic
Properties:
DisplayName: "apigateway-alarms"
TopicName: "apigateway-alarms"
Subscription:
-
Endpoint:
Ref: "AlarmEmail"
Protocol: "email"