-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserverless.yml
More file actions
434 lines (430 loc) · 13 KB
/
serverless.yml
File metadata and controls
434 lines (430 loc) · 13 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
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
# Welcome to Serverless!
#
#
# For full config options, check the docs:
# docs.serverless.com
#
# Happy Coding!
service: splitcloud-serverless-charts-service # NOTE: update this with your service name
package:
exclude:
- screenshots/**
- scripts
custom:
serverless-offline:
httpPort: 7777
domains:
prod: rest.splitcloud-app.com
dev: dev-rest.splitcloud-app.com
myStage: ${opt:stage, self:provider.stage}
prod:
ga_daily_extract: #cron(0 10 * * ? *)
sc_charts_cache: #rate(1 day)
schedule_token: #rate(3 minutes)
schedule_discovery: #rate(1 day)
schedule_country_charts: #cron(0 8 ? * MON *)
schedule_wrapped_aggregate: #cron(0 13 01 12 ? *)
schedule_import_promocodes: rate(1 day)
ddbReadUnit: 1
ddbWriteUnit: 1
country_charts_queue: "https://sqs.us-east-1.amazonaws.com/348868901434/splitcloud_charts_by_region"
country_charts_arn: "arn:aws:sqs:us-east-1:348868901434:splitcloud_charts_by_region"
charts_queue_enabled: false
ga_extractor_arn: "arn:aws:sqs:us-east-1:348868901434:ga_extractor_queue_prod"
ga_extractor_queue: "https://sqs.us-east-1.amazonaws.com/348868901434/ga_extractor_queue_prod"
ga_extractor_queue_enabled: false
firehose_event_bucket: "com.splitcloud-app.firehose.prod"
dev:
ga_daily_extract:
sc_charts_cache:
schedule:
schedule_token:
schedule_discovery:
schedule_country_charts:
schedule_wrapped_aggregate:
schedule_import_promocodes:
ddbReadUnit: 1
ddbWriteUnit: 1
country_charts_queue: "https://sqs.us-east-1.amazonaws.com/348868901434/splitcloud_charts_by_region_dev"
country_charts_arn: "arn:aws:sqs:us-east-1:348868901434:splitcloud_charts_by_region_dev"
charts_queue_enabled: true
ga_extractor_arn: "arn:aws:sqs:us-east-1:348868901434:ga_extractor_queue_dev"
ga_extractor_queue: "https://sqs.us-east-1.amazonaws.com/348868901434/ga_extractor_queue_dev"
ga_extractor_queue_enabled: false
firehose_event_bucket: "com.splitcloud-app.firehose.dev"
bucket: "www.splitcloud-app.com"
cache_bucket: "com.splitcloud-app.cache"
app_bucket: "com.splitcloud-app.app-sls"
rapsum_bucket: "trends.rapsum.com"
customDomain:
domainName: ${self:custom.domains.${self:custom.myStage}}
basePath: ''
stage: "${self:custom.myStage}"
createRoute53Record: true
# You can pin your service to only deploy with a specific Serverless version
# Check out our docs for more details
# frameworkVersion: "=X.X.X"
provider:
name: aws
runtime: nodejs12.x
timeout: 10
versionFunctions: false
apiGateway:
minimumCompressionSize: 2048
iamRoleStatements:
- Effect: Allow
Action:
- s3:*
Resource: "arn:aws:s3:::${self:custom.bucket}*"
- Effect: Allow
Action:
- s3:*
Resource: "arn:aws:s3:::${self:custom.rapsum_bucket}*"
- Effect: Allow
Action:
- s3:*
Resource: "arn:aws:s3:::${self:custom.cache_bucket}*"
- Effect: Allow
Action:
- s3:*
Resource: "arn:aws:s3:::${self:custom.app_bucket}*"
- Effect: Allow
Action:
- s3:*
Resource: "arn:aws:s3:::${self:custom.${self:custom.myStage}.firehose_event_bucket}*"
- Effect: Allow
Action:
- athena:*
Resource: "*"
- Effect: Allow
Action:
- glue:*
Resource: "*"
- Effect: Allow
Action:
- firehose:*
Resource: "*"
- Effect: "Allow"
Action:
- sqs:SendMessage
- sqs:GetQueueUrl
- sqs:ReceiveMessage
- sqs:DeleteMessage
Resource: ${self:custom.${self:custom.myStage}.country_charts_arn}
- Effect: "Allow"
Action:
- sqs:SendMessage
- sqs:GetQueueUrl
- sqs:ReceiveMessage
- sqs:DeleteMessage
Resource: ${self:custom.${self:custom.myStage}.ga_extractor_arn}
- Effect: Allow
Action:
- dynamodb:Query
- dynamodb:Scan
- dynamodb:GetItem
- dynamodb:PutItem
- dynamodb:UpdateItem
- dynamodb:DeleteItem
Resource: "arn:aws:dynamodb:${opt:region, self:provider.region}:*:table/${self:provider.environment.DYNAMODB_TABLE}"
environment:
BUCKET: ${self:custom.bucket}
STAGE: ${self:custom.myStage}
CACHE_BUCKET: ${self:custom.cache_bucket}
APP_BUCKET: ${self:custom.app_bucket}
RAPSUM_BUCKET: ${self:custom.rapsum_bucket}
COUNTRY_CHARTS_QUEUE: ${self:custom.${self:custom.myStage}.country_charts_queue}
GA_EXTRACTOR_QUEUE: ${self:custom.${self:custom.myStage}.ga_extractor_queue}
DYNAMODB_TABLE: ${self:service}-${self:custom.myStage}-db
KINESIS_STREAM_NAME: ${self:service}-${self:custom.myStage}-MyFirehose
KINESIS_STREAM_BUCKET: ${self:custom.${self:custom.myStage}.firehose_event_bucket}
resources:
Resources:
FirehoseEventBucket:
Type: 'AWS::S3::Bucket'
Properties:
BucketName: ${self:custom.${self:custom.myStage}.firehose_event_bucket}
AppDynamoDbTable:
Type: 'AWS::DynamoDB::Table'
DeletionPolicy: Retain
Properties:
AttributeDefinitions:
-
AttributeName: pk
AttributeType: S
-
AttributeName: sk
AttributeType: S
KeySchema:
-
AttributeName: pk
KeyType: HASH
-
AttributeName: sk
KeyType: "RANGE"
ProvisionedThroughput:
ReadCapacityUnits: ${self:custom.${self:custom.myStage}.ddbReadUnit}
WriteCapacityUnits: ${self:custom.${self:custom.myStage}.ddbWriteUnit}
TimeToLiveSpecification:
AttributeName: expireAt
Enabled: true
TableName: ${self:provider.environment.DYNAMODB_TABLE}
gaExtractorQueue:
Type: "AWS::SQS::Queue"
Properties:
QueueName: ga_extractor_queue_${self:custom.myStage}
FirehoseRole:
Type: AWS::IAM::Role
Properties:
RoleName: ${self:service}-${self:custom.myStage}-FirehoseRole
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- firehose.amazonaws.com
Action: sts:AssumeRole
Policies:
- PolicyName: root
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action: s3:*
Resource: "arn:aws:s3:::${self:custom.${self:custom.myStage}.firehose_event_bucket}*"
MyFirehose:
Type: AWS::KinesisFirehose::DeliveryStream
Properties:
DeliveryStreamName: ${self:service}-${self:custom.myStage}-MyFirehose
S3DestinationConfiguration:
BucketARN: "arn:aws:s3:::${self:custom.${self:custom.myStage}.firehose_event_bucket}"
BufferingHints:
IntervalInSeconds: 300
SizeInMBs: 50
CompressionFormat: UNCOMPRESSED
RoleARN:
Fn::GetAtt: [FirehoseRole, Arn]
functions:
#TODO: extract rapsum trends to own severless application
rapsum_trends:
handler: src/handlers/api.rapsumTrends
events:
- http:
path: rapsum/trends
method: get
charts_nowplay:
handler: src/handlers/api.nowPlaying
events:
- http:
enabled: false
path: charts/nowplaying
method: get
charts_endpoint:
handler: src/handlers/api.chartsEndpoint
events:
- http:
enabled: false
path: charts
method: get
searchTermsPopular:
handler: src/handlers/api.searchTermsPopular
events:
- http:
enabled: false
path: searchterms/popular
method: get
top_regions:
handler: src/handlers/api.topRegions
events:
- http:
enabled: false
path: regions
method: get
postsRegions:
handler: src/handlers/api.postsRegions
events:
- http:
enabled: false
path: posts/regions
method: get
log_collector:
timeout: 30
handler: src/handlers/api.logCollector
events:
- http:
path: app/feedback/{deviceid}
method: POST
request:
parameters:
paths:
deviceid: true
appReferrer:
handler: src/handlers/api.appReferrer
events:
- http:
enabled: true
path: app/referrer
method: POST
appPromoReferrer:
handler: src/handlers/api.appPromocodeRef
events:
- http:
enabled: true
path: app/promocode/referrer
method: POST
exploreRelated:
handler: src/handlers/api.exploreRelated
timeout: 15
events:
- http:
enabled: false
path: explore/related
method: POST
radio_countrycodes:
handler: src/handlers/api.radioCountryCodes
events:
- http:
path: radio/countrycodes
method: get
app_config_api:
handler: src/handlers/api.appConfigApi
events:
- http:
path: app/config
method: get
scResolve:
handler: src/handlers/api.scResolve
events:
- http:
enabled: false
path: /sc-proxy/resolve
method: get
eventIngest:
handler: src/handlers/api.eventIngest
events:
- http:
enabled: false
path: app/events/ingest
method: post
radioListByCountrycode:
handler: src/handlers/api.radioListByCountryCode
events:
- http:
enabled: false
path: radio/list/countrycode/{countrycode}
method: get
request:
parameters:
paths:
countrycode: true
globalYearWrapped:
handler: src/handlers/api.globalYearWrapped
timeout: 30
events:
- http:
enabled: false
path: wrapped/global/{kind}
method: get
yearWrapped:
handler: src/handlers/api.yearWrappedTopList
timeout: 30
events:
- http:
enabled: false
path: wrapped/{year}/{deviceId}/{side}
method: get
cors: true
request:
parameters:
paths:
year: true
deviceId: true
side: true
ctaEndpoint:
handler: src/handlers/api.ctaEndpoint
events:
- http:
enabled: true
path: cta/{deviceId}/{side}
method: get
cors: true
request:
parameters:
paths:
deviceId: true
side: true
# batch & offline running lambda functions
token:
handler: src/handlers/batch.selectActiveToken
timeout: 45
events:
- schedule: ${self:custom.${self:custom.myStage}.schedule_token}
discovery:
handler: src/handlers/batch.updateDiscoveryApi
timeout: 60
events:
- schedule: ${self:custom.${self:custom.myStage}.schedule_discovery}
chartsCache:
handler: src/handlers/batch.scChartsCache
timeout: 30
events:
- schedule: ${self:custom.${self:custom.myStage}.sc_charts_cache}
gaDailyExtract:
handler: src/handlers/batch.dailyGaEventExtract
timeout: 30
events:
- schedule: ${self:custom.${self:custom.myStage}.ga_daily_extract}
historyGaEventExtract:
handler: src/handlers/batch.historyGaEventExtract
timeout: 30
country_charts_pub:
handler: src/handlers/batch.countryChartsPublisher
timeout: 60
events:
- schedule: ${self:custom.${self:custom.myStage}.schedule_country_charts}
country_charts_sub:
handler: src/handlers/batch.countryChartsSubscribe
timeout: 120
reservedConcurrency: 2
events:
- sqs:
arn: ${self:custom.${self:custom.myStage}.country_charts_arn}
batchSize: 1
enabled: ${self:custom.${self:custom.myStage}.charts_queue_enabled}
rawGaEventExtractor:
handler: src/handlers/batch.rawGaEventExtractor
timeout: 30
events:
- sqs:
arn: ${self:custom.${self:custom.myStage}.ga_extractor_arn}
batchSize: 1
enabled: ${self:custom.${self:custom.myStage}.ga_extractor_queue_enabled}
batchWrapped:
handler: src/handlers/batch.computeWrappedAggregateTable
timeout: 60
events:
- schedule: ${self:custom.${self:custom.myStage}.schedule_wrapped_aggregate}
importPromocodes:
handler: src/handlers/batch.importPromocodesFromS3
timeout: 60
events:
- schedule: ${self:custom.${self:custom.myStage}.schedule_import_promocodes}
migrateRewarded:
handler: src/handlers/batch.migrateLegacyPromocodes
timeout: 60
# this s3 events don't seem to pickup changes it the latest deployed lambda
# if code seems not updated from the cloudwatch logs, deploy a version without
# any s3 bucket events and then re-deploy to re-enable the event to the new lambda version.
aggregatedNowPlaying:
handler: src/handlers/batch.aggregatedNowPlaying
timeout: 60
#events:
# - s3:
# existing: true
# bucket: ${self:custom.${self:custom.myStage}.firehose_event_bucket}
# event: s3:ObjectCreated:*
plugins:
- serverless-domain-manager
- serverless-offline
- serverless-prune-plugin