forked from SumoLogic/sumologic-aws-lambda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
KinesisFirehoseCWLogs.template.yaml
348 lines (326 loc) · 11.2 KB
/
KinesisFirehoseCWLogs.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
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
AWSTemplateFormatVersion: '2010-09-09'
Description: "Template to setup the AWS CloudWatch Logs collection using Amazon Kinesis Firehose and send the data to provided Sumo Logic URL."
Metadata:
AWS::ServerlessRepo::Application:
Author: Sumo Logic
Description: This solution helps to setup the AWS CloudWatch Logs collection using Amazon Kinesis Firehose and send the data to provided Sumo Logic URL.
HomePageUrl: https://github.com/SumoLogic/sumologic-aws-lambda
Labels:
- lambda
- sumologic
- serverless
- kinesis
- firehose
- cloudwatch
- logs
Name: sumologic-kinesis-cloudwatch-logs
SemanticVersion: 1.0.0
SourceCodeUrl: https://github.com/SumoLogic/sumologic-aws-lambda/tree/master/kinesis-firehose-cloudwatch-collection/logs
LicenseUrl: ./LICENSE
ReadmeUrl: ./README.md
SpdxLicenseId: Apache-2.0
'AWS::CloudFormation::Interface':
ParameterGroups:
- Label:
default: "1. Sumo Logic Kinesis Firehose Logs Configuration"
Parameters:
- Section1aSumoLogicKinesisLogsURL
- Label:
default: "2. Failed Data AWS S3 Bucket Configuration"
Parameters:
- Section2aCreateS3Bucket
- Section2bFailedDataS3Bucket
ParameterLabels:
Section1aSumoLogicKinesisLogsURL:
default: "Sumo Logic AWS Kinesis Firehose for Logs Source URL"
Section2aCreateS3Bucket:
default: "Create AWS S3 Bucket"
Section2bFailedDataS3Bucket:
default: "AWS S3 Bucket Name for Failed Data"
Parameters:
Section1aSumoLogicKinesisLogsURL:
Type: String
Description: "Provide HTTP Source Address from AWS Kinesis Firehose for Logs source created on your Sumo Logic account."
AllowedPattern: ".+"
ConstraintDescription: "Sumo Logic AWS Kinesis Firehose for Logs Source URL can not be empty."
Section2aCreateS3Bucket:
Type: String
Default: 'Yes'
Description: "Yes - Create a new AWS S3 Bucket to store failed data.'.
No - Use an existing AWS S3 Bucket to store failed data."
AllowedValues:
- 'Yes'
- 'No'
Section2bFailedDataS3Bucket:
Type: String
Description: "Provide a unique name of AWS S3 bucket where you would like to store Failed data. In case of existing AWS S3 bucket, provide the bucket from the current AWS Account. For Logs, failed data will be stored in folder prefix as SumoLogic-Kinesis-Failed-Logs."
AllowedPattern: "[a-z0-9-.]{3,63}$"
ConstraintDescription: "3-63 characters; must contain only lowercase letters, numbers, hyphen or period. For more details - https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucketnamingrules.html"
Conditions:
create_bucket: !Equals [ !Ref Section2aCreateS3Bucket, 'Yes' ]
Mappings:
ArnValue:
us-east-1:
ArnValue: "aws"
us-east-2:
ArnValue: "aws"
us-west-1:
ArnValue: "aws"
us-west-2:
ArnValue: "aws"
af-south-1:
ArnValue: "aws"
ca-central-1:
ArnValue: "aws"
eu-central-1:
ArnValue: "aws"
eu-west-1:
ArnValue: "aws"
eu-west-2:
ArnValue: "aws"
eu-south-1:
ArnValue: "aws"
eu-west-3:
ArnValue: "aws"
eu-north-1:
ArnValue: "aws"
ap-east-1:
ArnValue: "aws"
ap-northeast-1:
ArnValue: "aws"
ap-northeast-2:
ArnValue: "aws"
ap-northeast-3:
ArnValue: "aws"
ap-southeast-1:
ArnValue: "aws"
ap-southeast-2:
ArnValue: "aws"
ap-south-1:
ArnValue: "aws"
me-south-1:
ArnValue: "aws"
sa-east-1:
ArnValue: "aws"
us-gov-west-1:
ArnValue: "aws-us-gov"
us-gov-east-1:
ArnValue: "aws-us-gov"
cn-north-1:
ArnValue: "aws"
cn-northwest-1:
ArnValue: "aws"
Resources:
# Common Resources including creating bucket, create logs role and attach bucket policy.
FailedDataBucket:
Type: AWS::S3::Bucket
Condition: create_bucket
Metadata:
cfn_nag:
rules_to_suppress:
- id: W51
reason: "Role has been assigned permission to put logs in AWS S3 bucket."
- id: W35
reason: "Access logging not required for AWS S3 Bucket."
- id: W41
reason: "Encryption not required for AWS S3 Bucket."
Properties:
BucketName: !Ref Section2bFailedDataS3Bucket
AccessControl: Private
PublicAccessBlockConfiguration:
BlockPublicAcls: true
BlockPublicPolicy: true
IgnorePublicAcls: true
RestrictPublicBuckets: true
FirehoseLogsRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Sid: 'FirehoseAssumeRole'
Effect: Allow
Principal:
Service: firehose.amazonaws.com
Action: sts:AssumeRole
Condition:
StringEquals:
sts:ExternalId: !Ref "AWS::AccountId"
AttachBucketPolicyToFirehoseLogsRole:
Type: AWS::IAM::Policy
Properties:
PolicyName: "S3BucketPermissionPolicy"
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- s3:AbortMultipartUpload
- s3:GetBucketLocation
- s3:GetObject
- s3:ListBucket
- s3:ListBucketMultipartUploads
- s3:PutObject
Resource:
- !Sub
- "arn:${arn}:s3:::${S3Bucket}/*"
- arn: !FindInMap [ArnValue, !Ref "AWS::Region", ArnValue]
S3Bucket: !Ref Section2bFailedDataS3Bucket
- !Sub
- "arn:${arn}:s3:::${S3Bucket}"
- arn: !FindInMap [ArnValue, !Ref "AWS::Region", ArnValue]
S3Bucket: !Ref Section2bFailedDataS3Bucket
Roles:
- Ref: FirehoseLogsRole
# Resources for AWS Kinesis Logs including log group, stream, delivery stream, subscription filter, policy and role.
KinesisLogsLogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: !Sub
- "/aws/kinesisfirehose/Kinesis-Logs-${StackID}"
- StackID: !Select
- 0
- !Split
- "-"
- !Select
- 2
- !Split ["/", !Ref "AWS::StackId"]
RetentionInDays: 7
KinesisLogsLogStream:
Type: AWS::Logs::LogStream
Properties:
LogGroupName: !Ref KinesisLogsLogGroup
LogStreamName: "HttpEndpointDelivery"
KinesisLogsLogStreamS3:
Type: AWS::Logs::LogStream
Properties:
LogGroupName: !Ref KinesisLogsLogGroup
LogStreamName: "S3Delivery"
KinesisLogsRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Sid: 'LogsAssumeRole'
Effect: Allow
Principal:
Service: !Sub "logs.${AWS::Region}.amazonaws.com"
Action: sts:AssumeRole
KinesisLogsRolePolicy:
Type: AWS::IAM::Policy
Properties:
PolicyName: "KinesisFirehoseLogsPolicy"
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- firehose:PutRecord
- firehose:PutRecordBatch
- kinesis:PutRecord
- kinesis:PutRecordBatch
Resource: !Sub
- "arn:${arn}:firehose:${Region}:${AccountId}:*"
- arn: !FindInMap [ArnValue, !Ref "AWS::Region", ArnValue]
Region: !Ref "AWS::Region"
AccountId: !Ref "AWS::AccountId"
- Effect: Allow
Action:
- iam:PassRole
Resource: !Sub
- "arn:${arn}:iam::${AccountId}:role/${KinesisLogsRole}"
- arn: !FindInMap [ArnValue, !Ref "AWS::Region", ArnValue]
AccountId: !Ref "AWS::AccountId"
KinesisLogsRole: !Ref KinesisLogsRole
Roles:
- Ref: KinesisLogsRole
KinesisLogsDeliveryStream:
Type: AWS::KinesisFirehose::DeliveryStream
Properties:
DeliveryStreamName: !Sub
- "Kinesis-Logs-${StackID}"
- StackID: !Select
- 0
- !Split
- "-"
- !Select
- 2
- !Split ["/", !Ref "AWS::StackId"]
DeliveryStreamType: DirectPut
HttpEndpointDestinationConfiguration:
RoleARN: !GetAtt FirehoseLogsRole.Arn
EndpointConfiguration:
Url: !Ref Section1aSumoLogicKinesisLogsURL
Name: !Sub "${AWS::StackName}-sumologic-logs-endpoint"
RequestConfiguration:
ContentEncoding: GZIP
CloudWatchLoggingOptions:
Enabled: true
LogGroupName: !Ref KinesisLogsLogGroup
LogStreamName: !Ref KinesisLogsLogStream
BufferingHints:
IntervalInSeconds: 60
SizeInMBs: 4
RetryOptions:
DurationInSeconds: 60
S3BackupMode: FailedDataOnly
S3Configuration:
BucketARN: !If
- create_bucket
- !GetAtt FailedDataBucket.Arn
- !Sub
- "arn:${arn}:s3:::${S3Bucket}"
- arn: !FindInMap [ArnValue, !Ref "AWS::Region", ArnValue]
S3Bucket: !Ref Section2bFailedDataS3Bucket
CompressionFormat: UNCOMPRESSED
ErrorOutputPrefix: "SumoLogic-Kinesis-Failed-Logs/"
RoleARN: !GetAtt FirehoseLogsRole.Arn
CloudWatchLoggingOptions:
Enabled: true
LogGroupName: !Ref KinesisLogsLogGroup
LogStreamName: !Ref KinesisLogsLogStreamS3
KinesisLogsFirehoseRolePolicy:
Type: AWS::IAM::Policy
Properties:
PolicyName: "KinesisLogsLogStreamPermissionPolicy"
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- logs:PutLogEvents
Resource:
- !GetAtt KinesisLogsLogGroup.Arn
- !Sub "${KinesisLogsLogGroup.Arn}:log-stream:*"
- Effect: Allow
Action:
- kinesis:DescribeStream
- kinesis:GetShardIterator
- kinesis:GetRecords
- kinesis:ListShards
Resource:
- !GetAtt KinesisLogsDeliveryStream.Arn
Roles:
- Ref: FirehoseLogsRole
SubscriptionFilter:
Type: AWS::Logs::SubscriptionFilter
Properties:
RoleArn: !GetAtt KinesisLogsRole.Arn
LogGroupName: !Ref KinesisLogsLogGroup
FilterPattern: ''
DestinationArn: !GetAtt KinesisLogsDeliveryStream.Arn
Outputs:
FailedDataBucketArn:
Description: "S3 Bucket Arn where failed deliveries will be saved"
Condition: create_bucket
Value: !GetAtt FailedDataBucket.Arn
KinesisLogsDeliveryStreamARN:
Description: "The ARN for your Kinesis Firehose Delivery Stream, use this as the destination when adding CloudWatch Logs subscription filters."
Value: !GetAtt KinesisLogsDeliveryStream.Arn
KinesisLogsRoleARN:
Description: "The ARN for your CloudWatch Logs role to write to your delivery stream, use this as the role-arn when adding CloudWatch Logs subscription filters."
Value: !GetAtt KinesisLogsRole.Arn
KinesisLogsLogGroupARN:
Description: "The CloudWatch log group name where kinesis stream logs will be sent."
Value: !Ref KinesisLogsLogGroup