-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserverless.yml
247 lines (229 loc) · 6.45 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
service: be
package:
individually: true
patterns:
- '!node_modules/**'
- '!.venv/**'
useDotenv: ${self:custom.enableDotEnv.${self:provider.stage}}
provider:
name: aws
# profile: ${opt:aws-profile, "ntuscse"}
region: "ap-southeast-1"
apiName: be
stage: ${opt:stage, "dev"}
runtime: python3.9
iamRoleStatements:
- Effect: Allow
Action:
- dynamodb:Query
- dynamodb:Scan
- dynamodb:GetItem
- dynamodb:PutItem
- dynamodb:UpdateItem
- dynamodb:DeleteItem
- dynamodb:DescribeTable
Resource: "*"
environment:
SERVERLESS_STAGE: ${opt:stage, "dev"}
PRODUCT_CATEGORIES_TABLE_NAME: ${self:custom.tableNames.productCategoriesTableName}
PRODUCTS_TABLE_NAME: ${self:custom.tableNames.productsTableName}
ORDERS_TABLE_NAME: ${self:custom.tableNames.ordersTableName}
ORDER_HOLD_TABLE_NAME: ${self:custom.tableNames.ordersHoldTableName}
ORDER_EXPIRY_TIME: 1 # In hours
FRONTEND_HOST: ${env:FRONTEND_HOST, ssm:/FRONTEND_HOST_${self:provider.stage}}
plugins:
- serverless-python-requirements
- serverless-lift
- serverless-dotenv-plugin
- serverless-offline # serverless-offline needs to be last in the list
custom:
enableDotEnv:
dev: true
prod: false
pythonRequirements:
dockerizePip: false
usePoetry: true
serverless-offline:
allowCache: true
useChildProcesses: true
httpPort: 4000
tableNames:
productCategoriesTableName: 'be-${self:provider.stage}-product_categories'
productsTableName: 'be-${self:provider.stage}-products'
ordersTableName: 'be-${self:provider.stage}-orders'
ordersHoldTableName: 'be-${self:provider.stage}-orders-hold'
functions:
root:
handler: be.root.handler
environment:
STAGE: ${self:provider.stage}
events:
- http:
method: get
path: /
docs:
handler: be.docs.handler
environment:
STAGE: ${self:provider.stage}
events:
- http:
path: /docs
method: get
- http:
path: /openapi.json
method: get
- http:
path: /redoc
method: get
getOrder:
handler: be.api.v1.endpoints.orders.get.handler
environment:
STAGE: ${self:provider.stage}
events:
- http:
method: get
path: /orders/{proxy+}
getUsers:
handler: be.api.v1.endpoints.users.get.handler
environment:
STAGE: ${self:provider.stage}
events:
- http:
method: get
path: /users
- http:
method: get
path: /users/{proxy+}
getProducts:
handler: be.api.v1.endpoints.products.get.handler
environment:
STAGE: ${self:provider.stage}
events:
- http:
method: get
path: /products
cors: true
- http:
method: get
path: /products/{proxy+}
cors: true
getProductCategories:
handler: be.api.v1.endpoints.product_categories.get.handler
environment:
STAGE: ${self:provider.stage}
events:
- http:
method: get
path: /product-categories
- http:
method: get
path: /product-categories/{proxy+}
expire-unpaid-orders:
handler: be.api.v1.cron.expire_unpaid_orders.handler
environment:
STAGE: ${self:provider.stage}
events:
- schedule:
rate: cron(0 0 * * ? *)
enabled: true
postProductCategories:
handler: be.api.v1.endpoints.product_categories.post.handler
environment:
STAGE: ${self:provider.stage}
events:
- http:
method: post
path: /product-categories
postCartQuotation:
handler: be.api.v1.endpoints.cart.quotation.post.handler
environment:
STAGE: ${self:provider.stage}
events:
- http:
method: post
path: /cart/quotation
cors: true
postCartCheckout:
handler: be.api.v1.endpoints.cart.checkout.post.handler
environment:
STAGE: ${self:provider.stage}
STRIPE_SECRET_KEY: ${env:STRIPE_SECRET_KEY, ssm:/STRIPE_SECRET_KEY_${self:provider.stage}}
events:
- http:
method: post
path: /cart/checkout
cors: true
postPaymentsIntent:
handler: be.api.v1.endpoints.payments.intent.post.handler
environment:
STAGE: ${self:provider.stage}
STRIPE_SECRET_KEY: ${env:STRIPE_SECRET_KEY, ssm:/STRIPE_SECRET_KEY_${self:provider.stage}}
events:
- http:
method: post
path: /payments/intent
cors: true
postStripeWebhook:
handler: be.api.v1.endpoints.stripe_webhook.post.handler
environment:
STAGE: ${self:provider.stage}
STRIPE_SECRET_KEY: ${env:STRIPE_SECRET_KEY, ssm:/STRIPE_SECRET_KEY_${self:provider.stage}}
events:
- http:
method: post
path: /stripe_webhook
cors: true
resources:
Resources:
productCategoriesTable:
Type: 'AWS::DynamoDB::Table'
Properties:
TableName: ${self:provider.environment.PRODUCT_CATEGORIES_TABLE_NAME}
AttributeDefinitions:
- AttributeName: name
AttributeType: S
KeySchema:
- AttributeName: name
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
productsTable:
Type: 'AWS::DynamoDB::Table'
Properties:
TableName: ${self:provider.environment.PRODUCTS_TABLE_NAME}
AttributeDefinitions:
- AttributeName: id
AttributeType: S
KeySchema:
- AttributeName: id
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
ordersTable:
Type: 'AWS::DynamoDB::Table'
Properties:
TableName: ${self:provider.environment.ORDERS_TABLE_NAME}
AttributeDefinitions:
- AttributeName: orderID
AttributeType: S
KeySchema:
- AttributeName: orderID
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 2
WriteCapacityUnits: 2
ordersHoldTable:
Type: 'AWS::DynamoDB::Table'
Properties:
TableName: ${self:provider.environment.ORDER_HOLD_TABLE_NAME}
AttributeDefinitions:
- AttributeName: transactionID
AttributeType: S
KeySchema:
- AttributeName: transactionID
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 2
WriteCapacityUnits: 2