-
Notifications
You must be signed in to change notification settings - Fork 4
/
serverless.yml
266 lines (238 loc) · 7.83 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
# Copyright Fauna, Inc.
# SPDX-License-Identifier: MIT-0
service: serverless-fauna-example
configValidationMode: error
useDotenv: true
## If you use Serverless Framework Pro, uncomment the following two lines and replace with your app name and org.
# app: <Replace with your app name>
# org: <Replace with your org>
provider:
name: aws
runtime: nodejs12.x
lambdaHashingVersion: 20201221
environment:
FAUNA_SECRET: ${self:fauna.client.secret}
FAUNA_DOMAIN: ${self:fauna.client.domain}
FAUNA_SCHEME: ${self:fauna.client.scheme}
FAUNA_PORT: ${self:fauna.client.port}
plugins:
- "@fauna-labs/serverless-fauna"
functions:
seed:
handler: functions/seed.seed
list_products:
handler: functions/list_products.list
events:
- http:
method: get
path: /products
cors: true
request:
parameters:
headers:
secret: true
querystrings:
priceSort: false
customerId: false
storeId: false
environment:
products_by_store: ${self:fauna.indexes.products_by_store.name}
products_by_customer: ${self:fauna.indexes.products_by_customer.name}
all_products: ${self:fauna.indexes.all_products.name}
products_by_price_low_to_high: ${self:fauna.indexes.products_by_price_low_to_high.name}
products_by_price_high_to_low: ${self:fauna.indexes.products_by_price_high_to_low.name}
stores: ${self:fauna.collections.stores.name}
customers: ${self:fauna.collections.customers.name}
register:
handler: functions/register.create
events:
- http:
method: post
path: /customers
cors: true
request:
schemas:
application/json: ${file(./jsonSchemas/register.json)}
environment:
customer_by_email: ${self:fauna.indexes.customer_by_email.name}
customers: ${self:fauna.collections.customers.name}
login:
handler: functions/login.login
events:
- http:
method: post
path: /customers/login
cors: true
request:
schemas:
application/json: ${file(./jsonSchemas/login.json)}
environment:
customer_by_email: ${self:fauna.indexes.customer_by_email.name}
submit_order:
handler: functions/submit_order.submit
events:
- http:
method: post
path: /orders
cors: true
request:
parameters:
headers:
secret: true
schemas:
application/json: ${file(./jsonSchemas/submit_order.json)}
environment:
submit_order: ${self:fauna.functions.submit_order.name}
customer_orders:
handler: functions/customer_orders.list
events:
- http:
method: get
path: /orders
cors: true
request:
parameters:
headers:
secret: true
environment:
orders_by_customer: ${self:fauna.indexes.orders_by_customer.name}
fauna:
# The following declarations create the same collections, indexes, roles, and functions that
# are created if you select "Pre-populate with demo data" when creating a new database in the
# Fauna dashboard (https://dashboard.fauna.com).
#
# To populate the collections with the same demo data, deploy this application,
# then invoke the `seed` function:
# serverless deploy
# serverless invoke --function seed
client:
secret: ${env:FAUNA_SECRET}
domain: ${env:FAUNA_DOMAIN, "db.fauna.com"}
scheme: ${env:FAUNA_SCHEME, "https"}
port: ${env:FAUNA_PORT, "443"}
collections:
# Collections accept any parameter that CreateCollection() accepts.
# For more details on CreateCollection(), read https://docs.fauna.com/fauna/current/api/fql/functions/createcollection?lang=javascript#param_object
customers:
name: customers
data:
# Setting 'deletion_policy' to 'retain' leaves a resource intact if the entire application is removed with `serverless remove`.
# Typically you would set this to 'retain' for a production environment and leave it unset for environments that are
# frequently created and destroyed.
deletion_policy: retain
orders:
name: orders
products:
name: products
stores:
name: stores
indexes:
# Indexes accept any parameter that CreateIndex() accepts
# For more details on CreateIndex(), read https://docs.fauna.com/fauna/current/api/fql/functions/createindex?lang=javascript#param_object
orders_by_customer:
name: orders_by_customer
source: ${self:fauna.collections.orders.name}
terms:
fields:
- data.customer
products_by_customer:
name: products_by_customer
source: ${self:fauna.collections.orders.name}
terms:
fields:
- data.customer
values:
fields:
- data.cart.product
products_by_store:
name: products_by_store
source: ${self:fauna.collections.products.name}
terms:
fields:
- data.store
values:
fields:
- ref
products_by_price_high_to_low:
name: products_by_price_high_to_low
source: ${self:fauna.collections.products.name}
terms:
fields:
- ref
values:
fields:
- path: data.price
reverse: true
- ref
products_by_price_low_to_high:
name: products_by_price_low_to_high
source: ${self:fauna.collections.products.name}
terms:
fields:
- ref
values:
fields:
- data.price
- ref
customer_by_email:
name: customer_by_email
source: ${self:fauna.collections.customers.name}
data:
deletion_policy: retain
terms:
fields:
- data.email
all_orders:
name: all_orders
source: ${self:fauna.collections.orders.name}
all_customers:
name: all_customers
source: ${self:fauna.collections.customers.name}
all_stores:
name: all_stores
source: ${self:fauna.collections.stores.name}
all_products:
name: all_products
source: ${self:fauna.collections.products.name}
functions:
submit_order:
name: submit_order
body: ${file(./fql/SubmitOrder.fql)}
role: admin
roles:
# Roles accept any parameter that CreateRole() accepts
# For more details on CreateRole(), read https://docs.fauna.com/fauna/current/api/fql/functions/createrole?lang=javascript
customer:
name: customer
membership: ${self:fauna.collections.customers.name}
privileges:
- collection: ${self:fauna.collections.products.name}
actions:
read: true
- collection: ${self:fauna.collections.stores.name}
actions:
read: true
- collection: ${self:fauna.collections.orders.name}
actions:
read: ${file(./fql/Owner.fql)}
- index: ${self:fauna.indexes.all_products.name}
actions:
read: true
- index: ${self:fauna.indexes.products_by_store.name}
actions:
read: true
- index: ${self:fauna.indexes.products_by_price_low_to_high.name}
actions:
read: true
- index: ${self:fauna.indexes.products_by_price_high_to_low.name}
actions:
read: true
- index: ${self:fauna.indexes.orders_by_customer.name}
actions:
read: ${file(./fql/EqualsCurrentIdentityArity1.fql)}
- index: ${self:fauna.indexes.products_by_customer.name}
actions:
read: ${file(./fql/EqualsCurrentIdentityArity1.fql)}
- function: ${self:fauna.functions.submit_order.name}
actions:
call: ${file(./fql/EqualsCurrentIdentityArity2.fql)}