-
Notifications
You must be signed in to change notification settings - Fork 0
/
serverless.yml
333 lines (327 loc) · 8.64 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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
service:
name: backend
provider:
name: aws
runtime: nodejs10.x
stage: development
region: eu-central-1
tracing:
apiGateway: true
lambda: true
vpc:
securityGroupIds:
- Fn::GetAtt: ServerlessVPC.DefaultSecurityGroup
subnetIds:
- Ref: ServerlessSubnetA
- Ref: ServerlessSubnetB
- Ref: ServerlessSubnetC
iamRoleStatements:
- Effect: 'Allow'
Action:
- "logs:CreateLogGroup"
- "logs:CreateLogStream"
- "logs:PutLogEvents"
- "ec2:CreateNetworkInterface"
- "ec2:DescribeNetworkInterfaces"
- "ec2:DeleteNetworkInterface"
Resource: "*"
environment:
DB_HOST: ${self:custom.MySQL.HOST}
DB_PORT: ${self:custom.MySQL.PORT}
DB_NAME: ${self:custom.MySQL.DB_NAME}
DB_USERNAME: ${self:custom.MySQL.USERNAME}
DB_PASSWORD: ${self:custom.MySQL.PASSWORD}
# Define variables here for visibility
plugins:
- serverless-jetpack
- serverless-plugin-reducer
- serverless-offline
custom:
MySQL:
DB_NAME: aurora${opt:stage, self:provider.stage}
USERNAME: master
PASSWORD: ${ssm:/aws/reference/secretsmanager/dev/test/aurorapw~true}
HOST:
Fn::GetAtt: [MySQLRDSCluster, Endpoint.Address]
PORT:
Fn::GetAtt: [MySQLRDSCluster, Endpoint.Port]
VPC_CIDR: 10
package:
excludeDevDependencies: true
individually: false
include: "dist/**"
exclude:
- "src/**"
- ".idea/**"
- "*.json"
- "*.html"
- "*.log"
- "*.iml"
- "**/node_modules/aws-sdk/**"
- "webpack.config.js"
- "*.md"
- "LICENSE"
- "schemas/**"
functions:
authorize:
handler: dist/handlers/index.authorize
# GET ROUTES
getAllUnits:
handler: dist/handlers/index.getAllUnits
events:
- http:
method: get
path: unit
authorizer:
name: authorize
resultTtlInSeconds: 0
cors: true
getUnitDetails:
handler: dist/handlers/index.getUnitDetails
events:
- http:
method: get
path: unit/{id}
cors: true
authorizer:
name: authorize
resultTtlInSeconds: 0
request:
parameters:
paths:
id: true
getTaskDetails:
handler: dist/handlers/index.getTaskDetails
events:
- http:
method: get
path: task/{id}
cors: true
authorizer:
name: authorize
resultTtlInSeconds: 0
request:
parameters:
paths:
id: true
getQuestionDetails:
handler: dist/handlers/index.getQuestionDetails
events:
- http:
method: get
path: question/{id}
cors: true
authorizer:
name: authorize
resultTtlInSeconds: 0
request:
parameters:
paths:
id: true
seedDatabase:
handler: dist/handlers/index.seedDatabase
events:
- http:
method: get
path: seed
authorizer:
name: authorize
resultTtlInSeconds: 0
# POST ROUTES
submitAnswer:
handler: dist/handlers/index.submitAnswer
events:
- http:
method: post
path: answer
cors: true
authorizer:
name: authorize
resultTtlInSeconds: 0
request:
schema:
application/json: ${file(schemas/submit_answer.json)}
createQuestion:
handler: dist/handlers/backend/index.createQuestion
events:
- http:
method: post
path: question
cors: true
createTask:
handler: dist/handlers/backend/index.createTask
events:
- http:
method: post
path: task
cors: true
createTeam:
handler: dist/handlers/backend/index.createTeam
events:
- http:
method: post
path: team
cors: true
createTier:
handler: dist/handlers/backend/index.createTier
events:
- http:
method: post
path: tier
cors: true
createUnit:
handler: dist/handlers/backend/index.createUnit
events:
- http:
method: post
path: unit
cors: true
createUser:
handler: dist/handlers/backend/index.createUser
events:
- http:
method: post
path: user
cors: true
# PUT ROUTES
# modifyQuestion:
# handler: dist/handlers/backend/index.modifyQuestion
# events:
# - http:
# method: put
# path: question
# cors: true
# modifyTask:
# handler: dist/handlers/backend/index.modifyTask
# events:
# - http:
# method: put
# path: task
# cors: true
# modifyTeam:
# handler: dist/handlers/backend/index.modifyTeam
# events:
# - http:
# method: put
# path: team
# cors: true
# modifyUnit:
# handler: dist/handlers/backend/index.modifyUnit
# events:
# - http:
# method: put
# path: unit
# cors: true
# modifyUser:
# handler: dist/handlers/backend/index.modifyUser
# events:
# - http:
# method: put
# path: user
# cors: true
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'
GatewayResponseDefault5XX:
Type: 'AWS::ApiGateway::GatewayResponse'
Properties:
ResponseParameters:
gatewayresponse.header.Access-Control-Allow-Origin: "'*'"
gatewayresponse.header.Access-Control-Allow-Headers: "'*'"
ResponseType: DEFAULT_5XX
RestApiId:
Ref: 'ApiGatewayRestApi'
# VPC config
ServerlessVPC:
Type: AWS::EC2::VPC
Properties:
CidrBlock: ${self:custom.MySQL.VPC_CIDR}.0.0.0/16
EnableDnsSupport: true
EnableDnsHostnames: true
InstanceTenancy: default
ServerlessSubnetA:
DependsOn: ServerlessVPC
Type: AWS::EC2::Subnet
Properties:
VpcId:
Ref: ServerlessVPC
AvailabilityZone: ${self:provider.region}a
CidrBlock: ${self:custom.MySQL.VPC_CIDR}.0.0.0/24
ServerlessSubnetB:
DependsOn: ServerlessVPC
Type: AWS::EC2::Subnet
Properties:
VpcId:
Ref: ServerlessVPC
AvailabilityZone: ${self:provider.region}b
CidrBlock: ${self:custom.MySQL.VPC_CIDR}.0.1.0/24
ServerlessSubnetC:
DependsOn: ServerlessVPC
Type: AWS::EC2::Subnet
Properties:
VpcId:
Ref: ServerlessVPC
AvailabilityZone: ${self:provider.region}c
CidrBlock: ${self:custom.MySQL.VPC_CIDR}.0.2.0/24
# MySQL DB config
MySQLSubnetGroup:
Type: AWS::RDS::DBSubnetGroup
Properties:
DBSubnetGroupDescription: "MySQL Subnet Group"
SubnetIds:
- Ref: ServerlessSubnetA
- Ref: ServerlessSubnetB
- Ref: ServerlessSubnetC
MySQLRDSClusterParameter:
Type: AWS::RDS::DBClusterParameterGroup
Properties:
Description: Parameter group for the Serverless MySQL RDS DB.
Family: aurora-mysql5.7
Parameters:
character_set_database: "utf32"
MySQLRDSInstanceParameter:
Type: AWS::RDS::DBParameterGroup
Properties:
Description: Parameter group for the Serverless MySQL RDS DB.
Family: aurora-mysql5.7
Parameters:
sql_mode: IGNORE_SPACE
max_connections: 100
wait_timeout: 900
interactive_timeout: 900
MySQLRDSCluster:
Type: "AWS::RDS::DBCluster"
Properties:
MasterUsername: ${self:custom.MySQL.USERNAME}
MasterUserPassword: ${self:custom.MySQL.PASSWORD}
DBSubnetGroupName:
Ref: MySQLSubnetGroup
Engine: aurora-mysql
EngineVersion: "5.7"
DatabaseName: ${self:custom.MySQL.DB_NAME}
BackupRetentionPeriod: 3
DBClusterParameterGroupName:
Ref: MySQLRDSClusterParameter
VpcSecurityGroupIds:
- Fn::GetAtt: ServerlessVPC.DefaultSecurityGroup
MySQLRDSInstance:
Type: "AWS::RDS::DBInstance"
Properties:
DBInstanceClass: db.t2.small
DBSubnetGroupName:
Ref: MySQLSubnetGroup
Engine: aurora-mysql
EngineVersion: "5.7"
PubliclyAccessible: false
DBParameterGroupName:
Ref: MySQLRDSInstanceParameter
DBClusterIdentifier:
Ref: MySQLRDSCluster