-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserverless.yml
238 lines (232 loc) · 6.16 KB
/
serverless.yml
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
service: favi
provider:
name: aws
runtime: nodejs6.10
profile: tremorlab
apiKeys:
- favi-web-key
- favi-seed-key
usagePlan:
quota:
limit: 1000
period: DAY
throttle:
rateLimit: 5
burstLimit: 10
environment:
DEBUG: "*"
iamRoleStatements:
- Effect: Allow
Action:
- dynamodb:DescribeTable
- dynamodb:Query
- dynamodb:Scan
- dynamodb:GetItem
- dynamodb:PutItem
- dynamodb:UpdateItem
- dynamodb:DeleteItem
- dynamodb:GetRecords
- dynamodb:GetShardIterator
- dynamodb:DescribeStream
- dynamodb:ListStreams
- dynamodb:BatchWriteItem
- dynamodb:BatchGetItem
Resource: arn:aws:dynamodb:*:*
- Effect: Allow
Action:
- s3:*
Resource: arn:aws:s3:::favi-*/*
- Effect: "Allow"
Action:
- sns:*
Resource: "*"
- Effect: Allow
Action:
- lambda:InvokeFunction
- lambda:InvokeAsync
Resource: "*"
plugins:
- serverless-plugin-custom-domain
custom:
domain: "favi-api.andrhamm.com"
package:
exclude:
- app
- seed.rb
- '*.csv*'
- ruby
- vendor
- .bundle
- '*.rb'
- 'Gemfile*'
functions:
readFave:
description: HTTP-event function to lookup favicon data by hostname
handler: handlers/handler.readFave
events:
- http:
path: /faves
method: get
private: true
request:
parameters:
querystrings:
hostname: true
createFave:
description: HTTP-event function to queue a hostname for favicon scraping
handler: handlers/handler.createFave
events:
- http:
path: /faves
method: post
private: true
- http:
path: /faves
method: options
private: false
createFaveBatch:
description: Stream-event function to queue bulk hostnames for favicon scraping
handler: handlers/seed.createFaveBatch
events:
- sns: FaveSeeds
seedFaves:
description: HTTP-event function to queue a batch of hostnames for favicon scraping
handler: handlers/handler.seedFaves
timeout: 60
environment:
FAVI_SEED_KEY: ${file(env.yml):FAVI_SEED_KEY}
SNS_TOPIC_ARN: { "Ref": "SNSTopicFaveSeeds" }
events:
- http:
path: /seed
method: post
private: true
- http:
path: /seed
method: options
private: false
streamFaves:
description: HTTP-event function to queue a request to stream all faves to websocket
handler: handlers/handler.streamFaves
timeout: 60
events:
- http:
path: /faves/stream
method: post
private: true
- http:
path: /faves/stream
method: options
private: false
scrapeDynamoToSns:
description: Stream-event function to send dynamodb stream events to SNS
handler: handlers/handler.scrapeDynamoToSns
environment:
SNS_TOPIC_ARN: { "Ref": "SNSTopicFaveScrapeJobs" }
events:
- stream:
type: dynamodb
arn:
Fn::GetAtt:
- FavesDynamoDbTable
- StreamArn
batchSize: 25
scrapeFavicon:
description: Stream-event function to scrape favicons in a headlesss browser
handler: handlers/scrape.scrapeFavicon
timeout: 180
events:
- sns: FaveScrapeJobs
cacheFavicon:
description: Stream-event function to save copies of favicon images to S3
handler: handlers/cache.cacheFavicon
events:
- stream:
type: dynamodb
arn:
Fn::GetAtt:
- FavesDynamoDbTable
- StreamArn
batchSize: 25
notifyPusher:
description: Stream-event function to push dynamodb events to websockets
handler: handlers/notify.notifyPusher
environment:
PUSHER_APP_ID: ${file(env.yml):PUSHER_APP_ID}
PUSHER_KEY: ${file(env.yml):PUSHER_KEY}
PUSHER_SECRET: ${file(env.yml):PUSHER_SECRET}
events:
- stream:
type: dynamodb
arn:
Fn::GetAtt:
- FavesDynamoDbTable
- StreamArn
batchSize: 100
notifyPusherAll:
description: Function to push all faves to websockets
handler: handlers/notify.notifyPusherAll
environment:
PUSHER_APP_ID: ${file(env.yml):PUSHER_APP_ID}
PUSHER_KEY: ${file(env.yml):PUSHER_KEY}
PUSHER_SECRET: ${file(env.yml):PUSHER_SECRET}
resources:
Resources:
FavesDynamoDbTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: FaveRecords
AttributeDefinitions:
- AttributeName: hostname
AttributeType: "S"
KeySchema:
- AttributeName: hostname
KeyType: HASH
StreamSpecification:
StreamViewType: NEW_AND_OLD_IMAGES
ProvisionedThroughput:
ReadCapacityUnits: 25
WriteCapacityUnits: 25
S3BucketFaviApp:
Type: AWS::S3::Bucket
Properties:
BucketName: favi-app
S3BucketFaviCache:
Type: AWS::S3::Bucket
Properties:
BucketName: favi-cache
SNSTopicFaveSeeds:
Type: AWS::SNS::Topic
Properties:
TopicName: FaveSeeds
SNSTopicFaveScrapeJobs:
Type: AWS::SNS::Topic
Properties:
TopicName: FaveScrapeJobs
# KinesisTestMap:
# Type: AWS::Lambda::EventSourceMapping
# DependsOn :
# - "CreateFaveBatchLambdaFunction"
# - "IamPolicyLambdaExecution"
# Properties:
# BatchSize: 10
# EventSourceArn:
# Fn::GetAtt:
# - "KinesisStreamFaveSeeds"
# - "Arn"
# FunctionName:
# Fn::GetAtt:
# - "CreateFaveBatchLambdaFunction"
# - "Arn"
# StartingPosition: "TRIM_HORIZON"
# CloudFrontDistributionFaviApp:
# Type: AWS::CloudFront::Distribution
# Properties:
# DistributionConfig:
# Aliases:
# - favi.andrhamm.com
# DefaultRootObject: index.html
# Origins:
# - DomainName: favi.andrhamm.com
# Id: favi
# S3OriginConfig: