Repository navigation
Expand file tree
/
Copy pathserverless.yml
More file actions
370 lines (358 loc) · 10.8 KB
/
Copy pathserverless.yml
File metadata and controls
370 lines (358 loc) · 10.8 KB
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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
service: sls-data-pipelines
package:
individually: true
plugins:
- serverless-iam-roles-per-function
- serverless-python-requirements
- serverless-pseudo-parameters
custom:
lumigo:
token: ${ssm:/lumigo/token}
firehoseS3Prefix: 'destination/'
firehoseS3AnylticsResultsPrefix: 'analytics/results/'
firehoseCompressionFormat: UNCOMPRESSED
stage: "${opt:stage, self:provider.stage}"
provider:
name: aws
stage: dev
runtime: python3.8
region: eu-west-1
profile: default
httpApi:
cors:
allowedOrigins:
- '*'
allowedMethods:
- GET
- OPTIONS
reservedConcurrency: 1
memorySize: 512
versionFunctions: false
timeout: 30
iamRoleStatements:
- Effect: "Allow"
Action:
- "logs:CreateLogGroup"
- "logs:CreateLogStream"
- "logs:PutLogEvents"
Resource: '*'
environment:
LUMIGO_TRACER_TOKEN: ${ssm:/lumigo/token}
LUMIGO_ORIGINAL_HANDLER: handler.handle
functions:
RetrieveXMLTrafficData:
handler: /opt/python/lumigo_tracer._handler
module: src/RetrieveXMLTrafficData
timeout: 60
layers:
- arn:aws:lambda:eu-west-1:114300393969:layer:lumigo-python-tracer:115
environment:
TRAFFIC_DATA_URL: "http://miv.opendata.belfla.be/miv/verkeersdata"
BUCKET_NAME:
Ref: OriginBucket
S3_XML_PREFIX: "xml/input/"
iamRoleStatementsInherit: true
iamRoleStatements:
- Effect: "Allow"
Action:
- s3:PutObject
Resource:
Fn::Join:
- ""
- - "arn:aws:s3:::"
- Ref: "OriginBucket"
- "/*"
events:
- schedule:
rate: rate(1 minute)
enabled: false
TransformTrafficToJsonData:
handler: /opt/python/lumigo_tracer._handler
module: src/TransformTrafficDataToJson
layers:
- arn:aws:lambda:eu-west-1:114300393969:layer:lumigo-python-tracer:115
environment:
BUCKET_NAME:
Ref: OriginBucket
S3_XML_PREFIX: "xml/input/"
S3_JSON_PREFIX: "json/input/"
iamRoleStatementsInherit: true
iamRoleStatements:
- Effect: "Allow"
Action:
- s3:GetObject
- s3:PutObject
Resource:
Fn::Join:
- ""
- - "arn:aws:s3:::"
- Ref: "OriginBucket"
- "/*"
events:
- s3:
bucket:
Ref: OriginBucket
event: s3:ObjectCreated:*
rules:
- prefix: xml/input/
- suffix: .xml
existing: true
PublishTrafficData:
handler: /opt/python/lumigo_tracer._handler
module: src/PublishTrafficData
layers:
- arn:aws:lambda:eu-west-1:114300393969:layer:lumigo-python-tracer:115
environment:
BUCKET_NAME:
Ref: OriginBucket
S3_JSON_PREFIX: "json/input/"
DELIVERY_STREAM_NAME:
Ref: DeliveryStream
iamRoleStatementsInherit: true
iamRoleStatements:
- Effect: "Allow"
Action:
- s3:GetObject
Resource:
Fn::Join:
- ""
- - "arn:aws:s3:::"
- Ref: "OriginBucket"
- "/*"
- Effect: "Allow"
Action:
- "firehose:PutRecord"
- "firehose:PutRecordBatch"
Resource: { Fn::GetAtt: [ DeliveryStream, Arn ] }
events:
- s3:
bucket:
Ref: OriginBucket
event: s3:ObjectCreated:*
existing: true
rules:
- prefix: json/input/
- suffix: .json
StreamProcessor:
handler: /opt/python/lumigo_tracer._handler
module: src/StreamProcessor
timeout: 300
environment:
FILTER_IDS: '1897, 3159, 3977, 1065, 575'
layers:
- arn:aws:lambda:eu-west-1:114300393969:layer:lumigo-python-tracer:115
iamRoleStatementsInherit: true
iamRoleStatements:
- Effect: "Allow"
Action:
- "firehose:PutRecord"
- "firehose:PutRecordBatch"
Resource: !GetAtt DeliveryStream.Arn
StoreAnalyticsResultsPerPoint:
handler: /opt/python/lumigo_tracer._handler
module: src/StoreAnalyticsResultsPerPoint
timeout: 10
reservedConcurrency: 1
layers:
- arn:aws:lambda:eu-west-1:114300393969:layer:lumigo-python-tracer:115
environment:
TABLE_NAME: !Ref RealTimeAnalyticsPerPointTable
iamRoleStatementsInherit: true
iamRoleStatements:
- Effect: "Allow"
Action:
- "kinesis:DescribeStream"
- "kinesis:GetShardIterator"
- "kinesis:GetRecords"
Resource: !GetAtt DestinationStream.Arn
- Effect: "Allow"
Action:
- "dynamodb:DescribeStream"
- "dynamodb:DescribeTable"
- "dynamodb:BatchWrite*"
- "dynamodb:Delete*"
- "dynamodb:Update*"
- "dynamodb:PutItem"
Resource: !GetAtt RealTimeAnalyticsPerPointTable.Arn
- Effect: "Allow"
Action:
- "sqs:SendMessage"
- "sqs:ListQueues"
Resource: !GetAtt SaveAnalyticsDeadQueue.Arn
events:
- stream:
type: kinesis
arn: !GetAtt DestinationStream.Arn
batchWindow: 10
batchSize: 20
maximumRetryAttempts: 2
startingPosition: LATEST
enabled: true
destinations:
onFailure:
arn: !GetAtt SaveAnalyticsDeadQueue.Arn
type: sqs
PowerBiForwarderr:
# handler: /opt/python/lumigo_tracer._handler
handler: handler.handle
module: src/PowerBiForwarder
timeout: 10
reservedConcurrency: 1
# layers:
# - arn:aws:lambda:eu-west-1:114300393969:layer:lumigo-python-tracer:115
environment:
STEAMING_DATASET_URL: https://api.powerbi.com/beta/49c3d703-3579-47bf-a888-7c913fbdced9/datasets/a52e28e9-93f2-4c07-934f-52818e43536d/rows?noSignUpCheck=1&key=aYKSacZqpKWp7w1kUNI6KQJNejVi95yZkv%2FHJQDtLuZFrI3%2FhQkjYdoHsT9%2BoYSShdMZWQevrf5i77sdQHgYUA%3D%3D
iamRoleStatementsInherit: true
iamRoleStatements:
- Effect: "Allow"
Action:
- "kinesis:DescribeStream"
- "kinesis:GetShardIterator"
- "kinesis:GetRecords"
Resource: !GetAtt DestinationStream.Arn
- Effect: "Allow"
Action:
- "sqs:SendMessage"
- "sqs:ListQueues"
Resource: !GetAtt PowerBiForwarderDeadQueue.Arn
events:
- stream:
type: kinesis
arn: !GetAtt DestinationStream.Arn
batchWindow: 10
batchSize: 20
maximumRetryAttempts: 2
startingPosition: LATEST
enabled: true
destinations:
onFailure:
arn: !GetAtt PowerBiForwarderDeadQueue.Arn
type: sqs
AlertSaver:
handler: /opt/python/lumigo_tracer._handler
module: src/AlertSaver
timeout: 10
reservedConcurrency: 1
layers:
- arn:aws:lambda:eu-west-1:114300393969:layer:lumigo-python-tracer:115
environment:
TABLE_NAME: !Ref TrafficJamAlertsTable
iamRoleStatementsInherit: true
iamRoleStatements:
- Effect: "Allow"
Action:
- "dynamodb:DescribeStream"
- "dynamodb:DescribeTable"
- "dynamodb:BatchWrite*"
- "dynamodb:Delete*"
- "dynamodb:Update*"
- "dynamodb:PutItem"
Resource: !GetAtt RealTimeAnalyticsPerPointTable.Arn
- Effect: "Allow"
Action:
- "dynamodb:DescribeStream"
- "dynamodb:DescribeTable"
- "dynamodb:BatchWrite*"
- "dynamodb:Delete*"
- "dynamodb:Update*"
- "dynamodb:PutItem"
Resource: !GetAtt TrafficJamAlertsTable.Arn
events:
- stream:
type: dynamodb
arn:
Fn::GetAtt: [RealTimeAnalyticsPerPointTable, StreamArn]
maximumRetryAttempts: 2
AlertSender:
handler: /opt/python/lumigo_tracer._handler
module: src/AlertSender
timeout: 10
reservedConcurrency: 1
layers:
- arn:aws:lambda:eu-west-1:114300393969:layer:lumigo-python-tracer:115
environment:
SLACK_WEBHOOK: ${ssm:/slack/traffic/webhook}
SLACK_CHANNEL: traffic-alerts
FLASK_API: http://flask-env.eba-jp3gn4xp.eu-west-1.elasticbeanstalk.com/send-notification
iamRoleStatementsInherit: true
events:
- stream:
type: dynamodb
arn:
Fn::GetAtt: [TrafficJamAlertsTable, StreamArn]
maximumRetryAttempts: 2
CurrentSituation:
handler: /opt/python/lumigo_tracer._handler
module: src/CurrentSituation
timeout: 10
reservedConcurrency: 1
layers:
- arn:aws:lambda:eu-west-1:114300393969:layer:lumigo-python-tracer:115
environment:
TABLE_NAME: !Ref RealTimeAnalyticsPerPointTable
iamRoleStatementsInherit: true
iamRoleStatements:
- Effect: "Allow"
Action:
- "dynamodb:BatchGet*"
- "dynamodb:DescribeStream"
- "dynamodb:DescribeTable"
- "dynamodb:Get*"
- "dynamodb:Query"
- "dynamodb:Scan"
Resource: !GetAtt RealTimeAnalyticsPerPointTable.Arn
events:
- httpApi:
method: GET
path: /traffic
CurrentAlerts:
handler: /opt/python/lumigo_tracer._handler
module: src/CurrentAlerts
timeout: 10
reservedConcurrency: 1
layers:
- arn:aws:lambda:eu-west-1:114300393969:layer:lumigo-python-tracer:115
environment:
TABLE_NAME: !Ref TrafficJamAlertsTable
iamRoleStatementsInherit: true
iamRoleStatements:
- Effect: "Allow"
Action:
- "dynamodb:BatchGet*"
- "dynamodb:DescribeStream"
- "dynamodb:DescribeTable"
- "dynamodb:Get*"
- "dynamodb:Query"
- "dynamodb:Scan"
Resource: !GetAtt TrafficJamAlertsTable.Arn
events:
- httpApi:
method: GET
path: /alerts
resources:
- ${file(resources/firehose.yml)}
- ${file(resources/kinesis.yml)}
- ${file(resources/sqs.yml)}
- ${file(resources/s3.yml)}
- ${file(resources/dynamodb.yml)}
- ${file(resources/analytics.yml)}
- Outputs:
DeliveryStreamName:
Description: "Name of the firehose over which all traffic events flow"
Value: !Ref DeliveryStream
RealTimeAnalyticsPerPointTableName:
Description: "Single table that holds the analytics results"
Value: !Ref RealTimeAnalyticsPerPointTable
TrafficJamAlertsTableName:
Description: "Table that holds the traffic jam alerts"
Value: !Ref TrafficJamAlertsTable
OriginBucketName:
Description: "Bucket where input files are placed"
Value: !Ref OriginBucket
ResourcesBucketName:
Description: "Bucket where config files are placed"
Value: !Ref ResourcesBucket
TrafficEventsDeliveryBucket:
Value: !Ref DeliveryBucket
Export:
Name: ${self:service}-${opt:stage, self:provider.stage, 'dev'}-TrafficEventsDeliveryBucketName