-
Notifications
You must be signed in to change notification settings - Fork 0
/
serverless.yml
237 lines (228 loc) · 6.51 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
service: exit-market
custom:
serverless-offline:
port: 3001
table: exit-market-${opt:stage}
region: eu-west-1
kmsKeyArn: arn:aws:kms:eu-west-1:929106972464:key/${env:KMS_KEY_ID, ''}
package:
exclude:
- src/**/*.test.js
- '*.test.js'
provider:
name: aws
region: eu-west-1
runtime: nodejs8.10
timeout: 30
iamRoleStatements:
- Effect: Allow
Action:
- ssm:GetParameters
- ssm:GetParameter
Resource: "arn:aws:ssm:*:*:parameter/exit-market/${opt:stage}/*"
# Allow CRUD to usersTable with DynamoDb
- Effect: "Allow"
Action:
- dynamodb:Query
- dynamodb:Scan
- dynamodb:GetItem
- dynamodb:PutItem
- dynamodb:UpdateItem
- dynamodb:DeleteItem
Resource:
- Fn::GetAtt:
- exitMarketTable
- Arn
- "arn:aws:dynamodb:eu-west-1:*:table/${self:custom.table}/*"
- Effect: Allow
Action:
- KMS:Decrypt
Resource: ${self:custom.kmsKeyArn}
responseMappings: &response_mappings
headers:
Content-Type: "'application/json'"
statusCodes:
200:
pattern: ''
headers:
Access-Control-Allow-Origin: "'*'"
template:
application/json: ""
400:
pattern: 'Bad Request: .*'
headers:
Access-Control-Allow-Origin: "'*'"
template:
application/json: ""
401:
pattern: 'Unauthorized: .*'
headers:
Access-Control-Allow-Origin: "'*'"
template:
application/json: ""
403:
pattern: 'Forbidden: .*'
headers:
Access-Control-Allow-Origin: "'*'"
template:
application/json: ""
404:
pattern: 'Not Found: .*'
headers:
Access-Control-Allow-Origin: "'*'"
template:
application/json: ""
500:
pattern: 'Error: .*'
headers:
Access-Control-Allow-Origin: "'*'"
# Generic request mapping template. Should work for all the requests
# Reference:
# https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html
# https://serverless.com/framework/docs/providers/aws/events/apigateway#custom-request-templates
requestTemplate: &request_template
application/json: '
#set($allParams = $input.params())
{
"body": $input.json(''$''),
"params" : {
#foreach($type in $allParams.keySet())
#set($params = $allParams.get($type))
"$type" : {
#foreach($paramName in $params.keySet())
"$paramName" : "$util.escapeJavaScript($params.get($paramName))"
#if($foreach.hasNext),#end
#end
}
#if($foreach.hasNext),#end
#end
},
"context" : {
"http-method" : "$context.httpMethod",
"source-ip" : "$context.identity.sourceIp",
"user-agent" : "$context.identity.userAgent",
"resource-path" : "$context.resourcePath"
}
}'
functions:
manager:
timeout: 10
handler: src/exitManager/index.handler
name: exit-market-${opt:stage}-manager
environment:
TABLE_NAME: ${self:custom.table}
NODE_URL: ${env:NODE_URL}
MARKET_CONFIG: ${env:MARKET_CONFIG}
ENV: ${opt:stage}
events:
- http:
method: post
path: /sellExit
integration: lambda
cors: true
request:
passThrough: WHEN_NO_TEMPLATES
template: *request_template
response: *response_mappings
- http:
method: get
path: /exits/{account}/{color}
integration: lambda
cors: true
request:
parameters:
paths:
account: true
color: false
passThrough: WHEN_NO_TEMPLATES
template: *request_template
response: *response_mappings
- http:
method: get
path: /deals
integration: lambda
cors: true
request:
passThrough: WHEN_NO_TEMPLATES
template: *request_template
response: *response_mappings
- http:
method: post
path: /directSell
integration: lambda
cors: true
request:
passThrough: WHEN_NO_TEMPLATES
template: *request_template
response: *response_mappings
finalizer:
timeout: 120
handler: src/exitFinalizer/index.handler
name: exit-market-${opt:stage}-finalizer
environment:
TABLE_NAME: ${self:custom.table}
NODE_URL: ${env:NODE_URL}
MARKET_CONFIG: ${env:MARKET_CONFIG}
ENV: ${opt:stage}
events:
- schedule: rate(3 minutes)
plugins:
- serverless-webpack
- serverless-offline
resources:
Resources:
# Reference: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-dynamodb-table.html
exitMarketTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: ${self:custom.table}
AttributeDefinitions:
- AttributeName: utxoId
AttributeType: S
- AttributeName: color
AttributeType: N
- AttributeName: effectiveBlock
AttributeType: N
- AttributeName: account
AttributeType: S
- AttributeName: finalized
AttributeType: N
KeySchema:
- AttributeName: utxoId
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
GlobalSecondaryIndexes:
- IndexName: "block-index"
KeySchema:
- AttributeName: "color"
KeyType: "HASH"
- AttributeName: "effectiveBlock"
KeyType: "RANGE"
Projection:
NonKeyAttributes:
- "utxoId"
- "finalized"
- "txHash"
- "data"
ProjectionType: "INCLUDE"
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
- IndexName: "account-index"
KeySchema:
- AttributeName: "account"
KeyType: "HASH"
- AttributeName: "finalized"
KeyType: "RANGE"
Projection:
NonKeyAttributes:
- "utxoId"
- "color"
- "effectiveBlock"
- "value"
ProjectionType: "INCLUDE"
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1