generated from dynatrace-oss/template-project
-
Notifications
You must be signed in to change notification settings - Fork 5
/
dynatrace-aws-s3-log-forwarder-s3-bucket-configuration.yaml
320 lines (304 loc) · 11.8 KB
/
dynatrace-aws-s3-log-forwarder-s3-bucket-configuration.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
AWSTemplateFormatVersion: "2010-09-09"
Description: |
dynatrace-aws-s3-log-forwarder-s3-bucket-configuration
For a given AWS bucket and optionally between 1 up to 10 S3 Key prefixes, this AWS CloudFormation template does:
- Grant permissions to the dynatrace-aws-s3-log-forwarder Lambda function to GET objects from the specified S3 bucket and prefixes
- Create an Amazon EventBridge rule to send s3:ObjectCreated notifications on the specific S3 bucket and prefixes to the SQS queue
of the dynatrace-aws-s3-log-forwarder-s3
For more information: https://github.com/dynatrace-oss/dynatrace-aws-s3-log-forwarder
Metadata:
License:
Description: |
Copyright 2022 Dynatrace LLC
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
https://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.
Version:
Description: dev
Instructions:
Description: |
Deploy this template once per every Amazon S3 bucket you want to configure to forward logs to Dynatrace on the same AWS Account and region
where the dynatrace-aws-s3-log-forwarder is deployed. LogBucketPrefix# parameters are optional, only use them if you want to narrow down
the ingestion to specific prefixes in your bucket.
Example AWS CLI command:
aws cloudformation deploy \
--template-file s3-log-forwarder-bucket-config-template.yaml \
--stack-name dynatrace-aws-s3-log-forwarder-s3-bucket-configuration-{your-bucket-name} \
--parameter-overrides DynatraceAwsS3LogForwarderStackName={your-dynatrace-aws-s3-log-forwarder-stack-name} \
LogsBucketName={your-bucket-name} \
LogsBucketPrefix1={optional-bucket-prefix-1}/ \
LogsBucketPrefix2={optional-bucket-prefix-2}/ \
LogsBucketPrefix3={optional-bucket-prefix-3}/ \
--capabilities CAPABILITY_IAM
NOTE: If your S3 bucket is on a different AWS Region or AWS account, add the S3BucketIsCrossRegionOrCrossAccount=true parameter
don't forget to deploy the eventbridge-cross-{region|account}-forward-rules stack on AWS Region / Account where your S3 bucket is.
Once deployed, configure your S3 Bucket to send notifications to Amazon EventBridge following instructions here:
https://docs.aws.amazon.com/AmazonS3/latest/userguide/enable-event-notifications-eventbridge.html
Parameters:
DynatraceAwsS3LogForwarderStackName:
Type: String
Description: Name of the CloudFormation stack where you have deployed the dynatrace-aws-s3-log-forwarder
S3BucketIsCrossRegionOrCrossAccount:
Type: String
Description: If the bucket is on a different AWS account or region, set this value to true
Default: "false"
AllowedValues:
- "true"
- "false"
LogsBucketName:
Type: String
Description: Name of the S3 bucket to send "New Object Created" notifications to the dynatrace-aws-s3-log-forwarder
AllowedPattern: "^[0-9a-z]+([0-9a-z-.]{1,61}[0-9a-z])$"
LogsBucketPrefix1:
Type: String
Description: Prefix 1 to send logs from
Default: ""
LogsBucketPrefix2:
Type: String
Description: Prefix 2 to send logs from
Default: ""
LogsBucketPrefix3:
Type: String
Description: Prefix 3 to send logs from
Default: ""
LogsBucketPrefix4:
Type: String
Description: Prefix 4 to send logs from
Default: ""
LogsBucketPrefix5:
Type: String
Description: Prefix 5 to send logs from
Default: ""
LogsBucketPrefix6:
Type: String
Description: Prefix 6 to send logs from
Default: ""
LogsBucketPrefix7:
Type: String
Description: Prefix 7 to send logs from
Default: ""
LogsBucketPrefix8:
Type: String
Description: Prefix 8 to send logs from
Default: ""
LogsBucketPrefix9:
Type: String
Description: Prefix 9 to send logs from
Default: ""
LogsBucketPrefix10:
Type: String
Description: Prefix 10 to send logs from
Default: ""
Conditions:
FirstS3PrefixSpecified: !Not [!Equals [!Ref LogsBucketPrefix1, ""]]
SecondS3PrefixSpecified: !Not [!Equals [!Ref LogsBucketPrefix2, ""]]
ThirdS3PrefixSpecified: !Not [!Equals [!Ref LogsBucketPrefix3, ""]]
FourthS3PrefixSpecified: !Not [!Equals [!Ref LogsBucketPrefix4, ""]]
FithS3PrefixSpecified: !Not [!Equals [!Ref LogsBucketPrefix5, ""]]
SixthS3PrefixSpecified: !Not [!Equals [!Ref LogsBucketPrefix6, ""]]
SeventhS3PrefixSpecified: !Not [!Equals [!Ref LogsBucketPrefix7, ""]]
EighthS3PrefixSpecified: !Not [!Equals [!Ref LogsBucketPrefix8, ""]]
NinethS3PrefixSpecified: !Not [!Equals [!Ref LogsBucketPrefix9, ""]]
TenthS3PrefixSpecified: !Not [!Equals [!Ref LogsBucketPrefix10, ""]]
ConditionS3BucketIsCrossRegionOrCrossAccount: !Equals [ !Ref S3BucketIsCrossRegionOrCrossAccount, "true" ]
Resources:
LambdaS3Bucket1AccessIAMPolicy:
Type: AWS::IAM::Policy
Properties:
PolicyName: !Sub ${AWS::StackName}-ReadAccessToBucket
PolicyDocument:
Version: "2012-10-17"
Statement:
- Sid: "AllowGetObjectPermissions"
Effect: Allow
Action:
- s3:getObject
- s3:getObjectVersion
Resource:
- !Join
- ":"
- - arn
- !Sub ${AWS::Partition}
- s3
- ""
- ""
- !Sub ${LogsBucketName}/${LogsBucketPrefix1}*
- !If
- SecondS3PrefixSpecified
- !Join
- ":"
- - arn
- !Sub ${AWS::Partition}
- s3
- ""
- ""
- !Sub ${LogsBucketName}/${LogsBucketPrefix2}*
- !Ref "AWS::NoValue"
- !If
- ThirdS3PrefixSpecified
- !Join
- ":"
- - arn
- !Sub ${AWS::Partition}
- s3
- ""
- ""
- !Sub ${LogsBucketName}/${LogsBucketPrefix3}*
- !Ref "AWS::NoValue"
- !If
- FourthS3PrefixSpecified
- !Join
- ":"
- - arn
- !Sub ${AWS::Partition}
- s3
- ""
- ""
- !Sub ${LogsBucketName}/${LogsBucketPrefix4}*
- !Ref "AWS::NoValue"
- !If
- FithS3PrefixSpecified
- !Join
- ":"
- - arn
- !Sub ${AWS::Partition}
- s3
- ""
- ""
- !Sub ${LogsBucketName}/${LogsBucketPrefix5}*
- !Ref "AWS::NoValue"
- !If
- SixthS3PrefixSpecified
- !Join
- ":"
- - arn
- !Sub ${AWS::Partition}
- s3
- ""
- ""
- !Sub ${LogsBucketName}/${LogsBucketPrefix6}*
- !Ref "AWS::NoValue"
- !If
- SeventhS3PrefixSpecified
- !Join
- ":"
- - arn
- !Sub ${AWS::Partition}
- s3
- ""
- ""
- !Sub ${LogsBucketName}/${LogsBucketPrefix7}*
- !Ref "AWS::NoValue"
- !If
- EighthS3PrefixSpecified
- !Join
- ":"
- - arn
- !Sub ${AWS::Partition}
- s3
- ""
- ""
- !Sub ${LogsBucketName}/${LogsBucketPrefix8}*
- !Ref "AWS::NoValue"
- !If
- NinethS3PrefixSpecified
- !Join
- ":"
- - arn
- !Sub ${AWS::Partition}
- s3
- ""
- ""
- !Sub ${LogsBucketName}/${LogsBucketPrefix9}/*
- !Ref "AWS::NoValue"
- !If
- TenthS3PrefixSpecified
- !Join
- ":"
- - arn
- !Sub ${AWS::Partition}
- s3
- ""
- ""
- !Sub ${LogsBucketName}/${LogsBucketPrefix10*
- !Ref "AWS::NoValue"
Roles:
- Fn::ImportValue:
!Sub "${DynatraceAwsS3LogForwarderStackName}:QueueProcessingFunctionIamRole"
LogsBucketEventBridgeRule:
Type: AWS::Events::Rule
Properties:
Name:
!Join
- "-"
- - !Sub ${DynatraceAwsS3LogForwarderStackName}
# Get "random" string from AWS::StackId
- !Select [4, !Split ['-', !Select [2, !Split ['/', !Ref AWS::StackId]]]]
# If this rule is for a cross-region or cross-account bucket, create the rule on the dedicated bus
EventBusName:
!If
- ConditionS3BucketIsCrossRegionOrCrossAccount
- Fn::ImportValue:
Fn::Sub:
${DynatraceAwsS3LogForwarderStackName}:CrossRegionCrossAccountEventBusArn
- default
State: ENABLED
EventPattern:
source:
- "aws.s3"
detail-type:
- "Object Created"
detail:
bucket:
name:
- !Ref LogsBucketName
object:
key:
- !If
- FirstS3PrefixSpecified
- prefix: !Ref LogsBucketPrefix1
- prefix: ""
- !If
- SecondS3PrefixSpecified
- prefix: !Ref LogsBucketPrefix2
- !Ref AWS::NoValue
- !If
- ThirdS3PrefixSpecified
- prefix: !Ref LogsBucketPrefix3
- !Ref AWS::NoValue
- !If
- FourthS3PrefixSpecified
- prefix: !Ref LogsBucketPrefix4
- !Ref AWS::NoValue
- !If
- FithS3PrefixSpecified
- prefix: !Ref LogsBucketPrefix5
- !Ref AWS::NoValue
- !If
- SixthS3PrefixSpecified
- prefix: !Ref LogsBucketPrefix6
- !Ref AWS::NoValue
- !If
- EighthS3PrefixSpecified
- prefix: !Ref LogsBucketPrefix8
- !Ref AWS::NoValue
- !If
- NinethS3PrefixSpecified
- prefix: !Ref LogsBucketPrefix9
- !Ref AWS::NoValue
- !If
- TenthS3PrefixSpecified
- prefix: !Ref LogsBucketPrefix10
- !Ref AWS::NoValue
Targets:
- Id: "SQSQueue"
Arn:
Fn::ImportValue:
Fn::Sub:
${DynatraceAwsS3LogForwarderStackName}:S3NotificationsQueueArn