-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserverless.yml
386 lines (380 loc) · 9.55 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
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
service: livle-server
provider:
name: aws
runtime: nodejs6.10
region: ap-northeast-2
stage: dev
profile: livle-serverless
iamRoleStatements:
- Effect: "Allow"
Action:
- ec2:CreateNetworkInterface
- ec2:DescribeNetworkInterfaces
- ec2:DeleteNetworkInterface
Resource: "*"
- Effect: Allow
Action:
- s3:*
Resource: "arn:aws:s3:::livle"
- Effect: Allow
Action:
- s3:*
Resource: "arn:aws:s3:::livle/*"
- Effect: Allow
Action:
- ses:SendEmail
Resource: "*"
environment:
DB_NAME: ${file(./keys.yml):DB_NAME}
DB_HOST: ${file(./keys.yml):DB_HOST}
DB_PORT: ${file(./keys.yml):DB_PORT}
DB_USER: ${file(./keys.yml):DB_USER}
DB_PASS: ${file(./keys.yml):DB_PASS}
IMP_KEY: ${file(./keys.yml):IMP_KEY}
IMP_SECRET: ${file(./keys.yml):IMP_SECRET}
PUSHER_KEY: ${file(./keys.yml):PUSHER_KEY}
PUSHER_SECRET: ${file(./keys.yml):PUSHER_SECRET}
FCM_SERVER_KEY: ${file(./keys.yml):FCM_SERVER_KEY}
vpc:
securityGroupIds:
- "Fn::GetAtt": LivleSecurityGroup.GroupId
subnetIds:
- Ref: LivleSubnetA
- Ref: LivleSubnetC
plugins:
- serverless-domain-manager
- serverless-webpack
- serverless-offline
custom:
customDomain:
domainName: 'api.livle.kr'
certificateName: '*.livle.kr'
basePath: ${self:provider.stage}
stage: ${self:provider.stage}
createRoute53Record: true
webpackIncludeModules:
forceInclude:
- mysql2
package:
individually: true
functions:
userRouter:
handler: handler.userRouter
events:
- http:
path: user
method: any
cors: true
- http:
path: user/session
method: post
cors: true
- http:
path: user/facebook
method: post
cors: true
- http:
path: user/password
method: any
cors: true
- http:
path: user/list
method: get
cors: true
userUnsuspend:
handler: handler.userUnsuspend
events:
- http:
path: user/{userId}/suspend
method: delete
cors: true
partnerRouter:
handler: handler.partnerRouter
events:
- http:
path: partner
method: any
cors: true
partnerSignin:
handler: handler.partnerSignin
events:
- http:
path: partner/session
method: post
cors: true
partnerList:
handler: handler.partnerList
events:
- http:
path: partner/list
method: get
cors: true
partnerApprove:
handler: handler.partnerApprove
events:
- http:
path: partner/{partnerId}/approve
method: post
cors: true
ticketRouter:
handler: handler.ticketRouter
events:
- http:
path: ticket
method: any
cors: true
ticketList:
handler: handler.ticketList
events:
- http:
path: ticket/list
method: get
cors: true
ticketUpdate:
handler: handler.ticketUpdate
events:
- http:
path: ticket/{ticketId}
method: patch
cors: true
ticketDestroy:
handler: handler.ticketDestroy
events:
- http:
path: ticket/{ticketId}
method: delete
cors: true
ticketStats:
handler: handler.ticketStats
events:
- http:
path: ticket/{ticketId}/stats
method: get
cors: true
ticketReserve:
handler: handler.ticketReserve
events:
- http:
path: ticket/{ticketId}/reserve
method: post
cors: true
fileUpload:
handler: handler.fileUpload
events:
- http:
path: file
method: get
cors: true
subscriptionRouter:
handler: handler.subscriptionRouter
events:
- http:
path: subscription
method: any
cors: true
subscriptionLimit:
handler: handler.subscriptionLimit
events:
- http:
path: subscription/{subscriptionId}/limit
method: patch
cors: true
subscriptionRestore:
handler: handler.subscriptionRestore
events:
- http:
path: subscription/restore
method: post
cors: true
reservationRouter:
handler: handler.reservationRouter
events:
- http:
path: reservation
method: get
cors: true
- http:
path: reservation/{reservationId}
method: delete
cors: true
- http:
path: reservation/{reservationId}/check
method: post
cors: true
subscriptionRenew:
handler: handler.subscriptionRenew
events:
- schedule: cron(0 12 * * ? *) # Everyday 12pm UTC
noshowChecker:
handler: handler.noshowChecker
events:
- schedule: rate(1 hour) # Every hour
userDestroyer:
handler: handler.userDestroyer
events:
- schedule: cron(0 0 * * ? *) # Everyday 12am UTC
resources:
Resources:
LivleVPC:
Type: AWS::EC2::VPC
Properties:
CidrBlock: "10.0.0.0/16"
EnableDnsHostnames: true # For RDS to be publicly accessible
LivleSubnetA:
DependsOn: LivleVPC
Type: AWS::EC2::Subnet
Properties:
VpcId:
Ref: LivleVPC
AvailabilityZone: ${self:provider.region}a
CidrBlock: "10.0.0.0/24"
Tags:
- Key: 'Name'
Value: 'LivleSubnetA'
LivleSubnetC:
DependsOn: LivleVPC
Type: AWS::EC2::Subnet
Properties:
VpcId:
Ref: LivleVPC
AvailabilityZone: ${self:provider.region}c
CidrBlock: "10.0.1.0/24"
Tags:
- Key: 'Name'
Value: 'LivleSubnetC'
LivleSubnetIgw:
DependsOn: LivleVPC
Type: AWS::EC2::Subnet
Properties:
VpcId:
Ref: LivleVPC
AvailabilityZone: ${self:provider.region}c
CidrBlock: "10.0.2.0/24"
Tags:
- Key: 'Name'
Value: 'LivleSubnetIgw'
LivleInternetGateway:
Type: AWS::EC2::InternetGateway
LivleIgwAttachment:
Type: AWS::EC2::VPCGatewayAttachment
Properties:
InternetGatewayId:
Ref: LivleInternetGateway
VpcId:
Ref: LivleVPC
LivleIgwRouteTable:
Type: AWS::EC2::RouteTable
Properties:
VpcId:
Ref: LivleVPC
Tags:
- Key: 'Name'
Value: 'LivleIgwRouteTable'
LivleIgwRoute:
Type: AWS::EC2::Route
Properties:
DestinationCidrBlock: '0.0.0.0/0'
GatewayId:
Ref: LivleInternetGateway
RouteTableId:
Ref: LivleIgwRouteTable
LivleIgwRTSubnet:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId:
Ref: LivleIgwRouteTable
SubnetId:
Ref: LivleSubnetIgw
LivleNatEIP:
Type: AWS::EC2::EIP
Properties:
Domain: 'vpc'
LivleNatGateway:
Type: AWS::EC2::NatGateway
Properties:
AllocationId:
"Fn::GetAtt": LivleNatEIP.AllocationId
SubnetId:
Ref: LivleSubnetIgw
LivleNatRouteTable:
Type: AWS::EC2::RouteTable
Properties:
VpcId:
Ref: LivleVPC
Tags:
- Key: 'Name'
Value: 'LivleNatRouteTable'
LivleNatRoute:
Type: AWS::EC2::Route
Properties:
DestinationCidrBlock: '0.0.0.0/0'
NatGatewayId:
Ref: LivleNatGateway
RouteTableId:
Ref: LivleNatRouteTable
LivleNatSubnetA:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId:
Ref: LivleNatRouteTable
SubnetId:
Ref: LivleSubnetA
LivleNatSubnetC:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId:
Ref: LivleNatRouteTable
SubnetId:
Ref: LivleSubnetC
LivleSecurityGroup:
DependsOn: LivleVPC
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: SecurityGroup for Serverless Functions
VpcId:
Ref: LivleVPC
LivleStorageSecurityGroup:
DependsOn: LivleVPC
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Ingress for Memcached Cluster & RDS Instance
VpcId:
Ref: LivleVPC
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: '3306'
ToPort: '3306'
CidrIp: '0.0.0.0/0' # For development purpose
- IpProtocol: tcp
FromPort: '3306'
ToPort: '3306'
SourceSecurityGroupId:
Ref: LivleSecurityGroup
- IpProtocol: tcp
FromPort: '11211'
ToPort: '11211'
SourceSecurityGroupId:
Ref: LivleSecurityGroup
LivleRDSSubnetGroup:
Type: AWS::RDS::DBSubnetGroup
Properties:
DBSubnetGroupDescription: "RDS Subnet Group"
SubnetIds:
- Ref: LivleSubnetA
- Ref: LivleSubnetC
- Ref: LivleSubnetIgw
LivleRDSCluster:
DependsOn: LivleStorageSecurityGroup
Type: AWS::RDS::DBInstance
Properties:
Engine: mariadb
DBName: ${file(./keys.yml):DB_NAME}
MasterUsername: ${file(./keys.yml):DB_USER}
MasterUserPassword: ${file(./keys.yml):DB_PASS}
DBInstanceClass: db.t2.micro
AllocatedStorage: 10
VPCSecurityGroups:
- "Fn::GetAtt": LivleStorageSecurityGroup.GroupId
DBSubnetGroupName:
Ref: LivleRDSSubnetGroup
PubliclyAccessible: true