-
Notifications
You must be signed in to change notification settings - Fork 2
/
template.yaml
184 lines (181 loc) · 5.69 KB
/
template.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
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: API Interfaces and corresponding Lambda Functions for awsconfig.
Parameters:
AWSConfigTopicArn:
Type: String
Description: Arn of AWSConfig Topic
AWSConfigRulesLogGroupName:
Type: String
Default: "/SungardAS/Alerts/AWSConfigRules"
Description: AWSConfigRules Cloudwatch Log Group Name
SubscriptionFilterDestinationArn:
Type: String
Description: Subscription Filter Destination Arn
Resources:
ApiGatewayApi:
Type: AWS::Serverless::Api
Properties:
DefinitionUri: ./swagger.yaml
StageName: Prod
Variables:
LambdaFunctionName: !Ref LambdaFunction
LambdaFunctionIAMRole:
Type: "AWS::IAM::Role"
Properties:
Path: "/"
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
-
Sid: "AllowLambdaServiceToAssumeRole"
Effect: "Allow"
Action:
- "sts:AssumeRole"
Principal:
Service:
- "lambda.amazonaws.com"
Policies:
-
PolicyName: "InlinePolicy"
PolicyDocument:
Version: "2012-10-17"
Statement:
-
Effect: "Allow"
Action:
- "config:*"
- "iam:*"
- "lambda:*"
- "sns:Create*"
- "sns:Publish*"
- "sns:Get*"
- "sns:List*"
- "sns:Delete*"
- "sns:Subscribe*"
- "tag:Get*"
Resource: "*"
-
Effect: "Allow"
Action:
- "logs:CreateLogGroup"
- "logs:CreateLogStream"
- "logs:PutLogEvents"
Resource: "arn:aws:logs:*:*:*"
-
Effect: "Allow"
Action:
- "s3:PutObject*"
Resource: "arn:aws:s3:::*.awsconfig/AWSLogs/*/*"
Condition:
StringLike:
s3:x-amz-acl: "bucket-owner-full-control"
-
Effect: "Allow"
Action:
- "s3:GetBucketAcl"
Resource: "arn:aws:s3:::*.awsconfig"
-
Effect: "Allow"
Action:
- "s3:ListAllMyBuckets"
- "s3:CreateBucket"
Resource: "*"
-
Effect: "Allow"
Action:
- "sns:AddPermission"
Resource: "arn:aws:sns:*:*:awsconfig-topic"
LambdaFunction:
Type: AWS::Serverless::Function
Properties:
FunctionName: SungardAS-ConfigRules
Handler: index.handler
Runtime: nodejs8.10
CodeUri: ./src
Role: !GetAtt LambdaFunctionIAMRole.Arn
Timeout: 300
Events:
GetResource:
Type: Api
Properties:
RestApiId: !Ref ApiGatewayApi
Path: /{proxy+}
Method: ANY
AlertLambdaFunctionIAMRole:
Type: "AWS::IAM::Role"
Properties:
Path: "/"
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
-
Sid: "AllowAlertLambdaServiceToAssumeRole"
Effect: "Allow"
Action:
- "sts:AssumeRole"
Principal:
Service:
- "lambda.amazonaws.com"
Policies:
-
PolicyName: "InlinePolicy"
PolicyDocument:
Version: "2012-10-17"
Statement:
-
Effect: "Allow"
Action:
- "logs:CreateLogGroup"
- "logs:CreateLogStream"
- "logs:PutLogEvents"
Resource: "arn:aws:logs:*:*:*"
-
Effect: "Allow"
Action:
- "cloudwatchlogs:*"
Resource: "*"
CloudWatchLogsFunction:
Type: AWS::Serverless::Function
Properties:
FunctionName: SungardAS-ConfigRules-CloudwatchLogs
Handler: index_cloudwatchlogs.handler
Runtime: nodejs8.10
CodeUri: ./src
Role: !GetAtt AlertLambdaFunctionIAMRole.Arn
Timeout: 60
Environment:
Variables:
AWSCONFIGRULES_LOG_GROUP_NAME: !Ref AWSConfigRulesLogGroupName
Events:
AWSConfigTopic:
Type: SNS
Properties:
Topic: !Ref AWSConfigTopicArn
AWSConfigRulesLogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: !Ref AWSConfigRulesLogGroupName
SubscriptionFilter:
Type: AWS::Logs::SubscriptionFilter
DependsOn: AWSConfigRulesLogGroup
Properties:
LogGroupName: !Ref AWSConfigRulesLogGroupName
FilterPattern: ""
DestinationArn: !Ref SubscriptionFilterDestinationArn
Outputs:
APIURL:
Description: "URL of your API endpoint"
Value: !Join
- ''
- - https://
- !Ref ApiGatewayApi
- '.execute-api.'
- !Ref 'AWS::Region'
- '.amazonaws.com/Prod'
LambdaFunctionArn:
Description: "Lambda Function ARN"
Value: !GetAtt LambdaFunction.Arn
CloudWatchLogsLambdaFunctionArn:
Description: "CloudWatchLogs Lambda Function ARN"
Value: !GetAtt CloudWatchLogsFunction.Arn