-
Notifications
You must be signed in to change notification settings - Fork 1
/
serverless.yml
254 lines (242 loc) · 6.56 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
service: memestock
frameworkVersion: '2'
plugins:
- serverless-bundle
# - serverless-pseudo-parameters # Not necessary with Serverless >2.3.x
- serverless-offline
- serverless-cloudside-plugin
provider:
name: aws
region: us-east-1
runtime: nodejs12.x
memorySize: 256
# stage: ${opt:stage, dev}
apiGateway:
shouldStartNameWithService: true
lambdaHashingVersion: '20201221'
environment:
MAIN_TABLE_NAME: !Ref MemeStockMainTable
COGNITO_GENERIC_USER_POOL_ID: !Ref GenericUserPool
COGNITO_GENERIC_USER_CLIENT_ID: !Ref GenericUserClient
ORDER_STATUS_AND_SK_GSI: orderStatusAndSk
iamRoleStatements:
- Effect: Allow
Action:
- dynamodb:Scan
- dynamodb:Query
- dynamodb:PutItem
- dynamodb:GetItem
- dynamodb:UpdateItem
Resource:
- !GetAtt MemeStockMainTable.Arn
- !Join ['/', [!GetAtt MemeStockMainTable.Arn, 'index', '*']]
- Effect: Allow
Action:
- 'cognito-idp:AdminConfirmSignUp'
- 'cognito-idp:AdminCreateUser'
- 'cognito-idp:AdminGetUser'
- 'cognito-idp:AdminSetUserPassword'
- 'cognito-idp:AdminUpdateUserAttributes'
- 'cognito-idp:DescribeUserPool'
Resource:
- !GetAtt GenericUserPool.Arn
custom:
serverless-offline:
httpPort: 4321
resources:
Resources:
GatewayResponseDefault4XX:
Type: 'AWS::ApiGateway::GatewayResponse'
Properties:
ResponseParameters:
gatewayresponse.header.Access-Control-Allow-Origin: "'*'"
gatewayresponse.header.Access-Control-Allow-Headers: "'*'"
ResponseType: DEFAULT_4XX
RestApiId:
Ref: 'ApiGatewayRestApi'
MemeStockMainTable:
Type: AWS::DynamoDB::Table
Properties:
# TableName: MemeStockMainTable-${self:provider.stage}
TableName: MemeStockMainTable
BillingMode: PAY_PER_REQUEST
AttributeDefinitions:
- AttributeName: pk
AttributeType: S
- AttributeName: sk
AttributeType: S
- AttributeName: orderStatus
AttributeType: S
KeySchema:
- AttributeName: pk
KeyType: HASH
- AttributeName: sk
KeyType: RANGE
GlobalSecondaryIndexes:
- IndexName: orderStatusAndSk
KeySchema:
- AttributeName: orderStatus
KeyType: HASH
- AttributeName: sk
KeyType: RANGE
Projection:
ProjectionType: ALL
GenericUserAuthorizer:
DependsOn:
- ApiGatewayRestApi
Type: AWS::ApiGateway::Authorizer
Properties:
Name: generic-user-authorizer
IdentitySource: method.request.header.Authorization
# AuthorizerResultTtlInSeconds is to solve a caching issue described here:
# https://stackoverflow.com/questions/50331588/aws-api-gateway-custom-authorizer-strange-showing-error#answer-56119016
# Though, there may be more elegant ways of handling this in the authorizer
# allow policy
AuthorizerResultTtlInSeconds: 0
RestApiId:
Ref: ApiGatewayRestApi
Type: COGNITO_USER_POOLS
ProviderARNs:
- Fn::GetAtt: [GenericUserPool, Arn]
GenericUserClient:
Type: 'AWS::Cognito::UserPoolClient'
Properties:
ClientName: memestock-generic-user-client
GenerateSecret: False
UserPoolId:
Ref: GenericUserPool
ExplicitAuthFlows:
- ALLOW_USER_PASSWORD_AUTH
- ALLOW_REFRESH_TOKEN_AUTH
- ALLOW_ADMIN_USER_PASSWORD_AUTH
GenericUserPool:
Type: 'AWS::Cognito::UserPool'
Properties:
UserPoolName: memestock-generic-user
MfaConfiguration: 'OFF'
# AccountRecoverySetting:
# - email
AliasAttributes:
- email
- preferred_username
# UsernameAttributes:
# - email
# - 'userId'
# - 'username'
Schema:
- Name: email
Required: true
Mutable: true
- Name: 'userId'
Mutable: false
AttributeDataType: String
Policies:
PasswordPolicy:
MinimumLength: 6
RequireLowercase: False
RequireNumbers: True
RequireSymbols: False
RequireUppercase: True
functions:
users:
handler: handlers/users.handler
events:
- http:
method: get
path: users
cors: true
authorizer: genericUserAuthorizer
- http:
method: post
path: users
- http:
method: post
path: users/signup
cors: true
- http:
method: post
path: users/login
cors: true
- http:
method: put
path: users
- http:
method: delete
path: users
companies:
handler: handlers/companies.handler
events:
- http:
method: get
path: companies
cors: true
- http:
method: get
path: companies/stock-price
cors: true
- http:
method: post
path: companies
- http:
method: put
path: companies
- http:
method: delete
path: companies
ai:
handler: handlers/ai.handler
events:
- http:
method: get
path: ai
- http:
method: post
path: ai
- http:
method: put
path: ai
- http:
method: delete
path: ai
- http:
method: get
path: ai/action
executeAiAction:
handler: handlers/ai.executeAiAction
# events:
# - schedule:
# rate: rate(1 minute)
# enabled: true
orders:
handler: handlers/orders.handler
events:
- http:
method: get
path: orders
cors: true
- http:
method: get
path: orders/history
cors: true
authorizer: genericUserAuthorizer
- http:
method: get
path: orders/feed
cors: true
- http:
method: get
path: orders/count/{orderStatus}
cors: true
- http:
method: post
path: orders
cors: true
authorizer: genericUserAuthorizer
- http:
method: put
path: orders
cors: true
testAuthorizer:
handler: handlers/authorizers.testAuthorizer
genericUserAuthorizer:
handler: handlers/authorizers.genericUserAuthorizer