forked from DefiLlama/yield-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
serverless.yml
280 lines (256 loc) · 7.18 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
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
service: llama-apy
package:
individually: true
frameworkVersion: '3'
provider:
name: aws
runtime: nodejs14.x
stage: dev
region: eu-central-1
tracing:
apiGateway: true
lambda: true
memorySize: 256
iam:
role:
statements:
- Effect: Allow
Action:
- xray:PutTraceSegments
- xray:PutTelemetryRecords
Resource: '*'
- Effect: Allow
Action:
- s3:ListBucket
- s3:*Object*
- sqs:SendMessage
Resource: '*'
- Effect: Allow
Action:
- ssm:PutParameter
- ssm:GetParameter
- ssm:DescribeParameters
- kms:Decrypt
Resource: '*'
environment:
# for entrypoint and enrichment
ADAPTORS: ${file(./env.js):ADAPTORS}
# for api handlers
APIG_URL:
{
'Fn::Join':
[
'',
[
'https://',
{ Ref: 'HttpApi' },
'.execute-api.',
{ Ref: 'AWS::Region' },
'.',
{ Ref: 'AWS::URLSuffix' },
],
],
}
SSM_PATH: ${self:custom.ssmPath}
BUCKET_DATA: { Ref: BucketData }
httpApi:
metrics: true
cors:
allowedMethods:
- GET
authorizers:
JwtAuthorizer:
type: jwt
identitySource: $request.header.Authorization
issuerUrl: ${ssm:${self:custom.ssmPath}/issuer}
audience: ${ssm:${self:custom.ssmPath}/audience}
functions:
triggerAuthenticate:
handler: src/handlers/triggerAuthenticate.handler
description: Lambda to create bearer token which stores to ssm
timeout: 30
events:
# every 12hours
- schedule: rate(12 hours)
# --- top-lvl-entrypoint
triggerEntrypoint:
handler: src/handlers/triggerEntrypoint.handler
description: Lambda to launch the adaptor pipeline
timeout: 30
events:
# every new hour
- schedule: cron(0 * * * ? *)
environment:
ADAPTER_QUEUE_URL: { Ref: AdapterQueue }
# --- adaptors
triggerAdaptor:
handler: src/handlers/triggerAdaptor.handler
description: Lambda which runs adaptors
timeout: 600
events:
- sqs:
arn:
Fn::GetAtt:
- AdapterQueue
- Arn
batchSize: 2
functionResponseType: ReportBatchItemFailures
environment:
ETHERSCAN: ${file(./env.js):ETHERSCAN}
FANTOMSCAN: ${file(./env.js):FANTOMSCAN}
POLYGONSCAN: ${file(./env.js):POLYGONSCAN}
SNOWTRACE: ${file(./env.js):SNOWTRACE}
ARBISCAN: ${file(./env.js):ARBISCAN}
OPTIMISM: ${file(./env.js):OPTIMISM}
INFURA_CONNECTION: ${file(./env.js):INFURA_CONNECTION}
ALCHEMY_CONNECTION_POLYGON: ${file(./env.js):ALCHEMY_CONNECTION_POLYGON}
ALCHEMY_CONNECTION_ARBITRUM: ${file(./env.js):ALCHEMY_CONNECTION_ARBITRUM}
# --- data enrichment (pct-changes)
triggerEnrichment:
handler: src/handlers/triggerEnrichment.handler
description: Lambda which runs enrichment process
timeout: 300
events:
# every hour at 20 past
- schedule: cron(20 * * * ? *)
# --- DB Crud operations
getPools:
handler: src/handlers/getPools.handler
description: Lambda for retrieving the latest data for each unique pool
timeout: 20
events:
- httpApi:
method: get
path: /pools
storePools:
handler: src/handlers/storePools.handler
description: Lambda for db bulkwrite
timeout: 20
events:
- httpApi:
method: post
path: /pools
authorizer:
name: JwtAuthorizer
deletePools:
handler: src/handlers/deletePools.handler
description: Lambda for deleteMany operation of pool data
timeout: 20
events:
- httpApi:
method: delete
path: /pools/{project}/{timestamp}
authorizer:
name: JwtAuthorizer
getPoolsEnriched:
handler: src/handlers/getPoolsEnriched.handler
description: Lambda for retrieving the latest enriched data for each unique pool
timeout: 20
events:
- httpApi:
method: get
path: /poolsEnriched
getChart:
handler: src/handlers/getChart.handler
description: Lambda for retrieving chart data for a particular pool
timeout: 20
events:
- httpApi:
method: get
path: /chart/{pool}
getOffsets:
handler: src/handlers/getOffsets.handler
description: Lambda for getting 1/7/30 day offset data of apy values
timeout: 20
events:
- httpApi:
method: get
path: /offsets/{project}/{days}
getStds:
handler: src/handlers/getStds.handler
description: Lambda for retrieving std data
timeout: 20
events:
- httpApi:
method: get
path: /stds
storeStds:
handler: src/handlers/storeStds.handler
description: Lambda for db bulkupdate of std data
timeout: 20
events:
- httpApi:
method: post
path: /stds
authorizer:
name: JwtAuthorizer
resources:
Resources:
# QUEUES
# --- queue for adaptor handler
AdapterQueue:
Type: AWS::SQS::Queue
Properties:
QueueName: ${self:service}-${self:custom.stage}-AdapterQueue
VisibilityTimeout: 660
# setting this to 9hours
MessageRetentionPeriod: 32400
RedrivePolicy:
deadLetterTargetArn:
Fn::GetAtt:
- DeadLetterQueue
- Arn
# this params is requried, otherwise cloudformation error
# means that after 3 failed runs, the message will be moved from the adaptor queue
# to the DLQ
maxReceiveCount: 3
# --- DLQ
DeadLetterQueue:
Type: AWS::SQS::Queue
Properties:
QueueName: ${self:service}-${self:custom.stage}-DeadLetterQueue
# leaving this at max, 14days, after that msg in there will be deleted
MessageRetentionPeriod: 1209600
# --- create bucket
BucketData:
Type: AWS::S3::Bucket
Properties:
BucketName: ${self:service}-${self:custom.stage}-data
# --- alarm stuff for DLQ
DlqAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmName: ${self:service}-${self:custom.stage}-AdapterDLQ
AlarmDescription: There are failed messages in the dead letter queue.
Namespace: AWS/SQS
MetricName: ApproximateNumberOfMessagesVisible
Dimensions:
- Name: QueueName
Value: !GetAtt DeadLetterQueue.QueueName
Statistic: Sum
Period: 60
EvaluationPeriods: 1
Threshold: 0
ComparisonOperator: GreaterThanThreshold
AlarmActions:
- !Ref DlqAlarmEmail
DlqAlarmEmail:
Type: AWS::SNS::Topic
Properties:
Subscription:
- Endpoint: [email protected]
Protocol: email
custom:
stage: ${opt:stage, self:provider.stage}
ssmPath: /${self:service}/serverless/sls-authenticate
webpack:
webpackConfig: 'webpack.config.js'
includeModules: true
packager: 'npm'
excludeFiles: src/**/*.test.js
prune:
automatic: true
number: 5
plugins:
- serverless-webpack
- serverless-prune-plugin