-
Notifications
You must be signed in to change notification settings - Fork 34
/
serverless.yml
269 lines (255 loc) · 6.99 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
service: trash-panda-buffet-test
frameworkVersion: '2'
variablesResolutionMode: 20210326
custom:
client:
bucketName: tpb-assets-<your_name>
distributionFolder: src/client/dist
cloudFrontDistributionId: trash-panda-buffet-test
cloudfrontInvalidate:
- distributionIdKey: cloudFrontDistributionOutput
items:
- '/assets/*'
database:
name: trashPandaBuffet
password: pandabear
username: trash
groupName: trash-panda-buffet
kinesis:
streamName: trash-panda-buffet
partitionKey: food-action
vpc:
securityGroupIds:
- Fn::GetAtt: [ trashPandaSecurityGroup, GroupId ]
subnetIds:
- Ref: trashPandaSubnetA
- Ref: trashPandaSubnetB
provider:
name: aws
runtime: nodejs14.x
region: ${file(./helpers/region.js)}
lambdaHashingVersion: 20201221
iamRoleStatements:
- Effect: Allow
Action:
- cloudfront:GetDistribution
- kinesis:GetRecords
- kinesis:PutRecord
Resource: '*'
environment:
DB_ADDRESS:
Fn::GetAtt: [ gameDBCluster, Endpoint.Address ]
DB_NAME: ${self:custom.database.name}
DB_PASSWORD: ${self:custom.database.password}
DB_USERNAME: ${self:custom.database.username}
tags:
Group: ${self:custom.groupName}
functions:
index:
handler: src/lambda/static.index
environment:
CLIENT_BUCKET: ${self:custom.client.bucketName}
CLOUDFRONT_DOMAIN:
Fn::GetAtt: [ assetsCloudFrontDistribution, DomainName ]
events:
- http:
path: /
method: get
gameStart:
handler: src/lambda/game.init
vpc: ${self:custom.vpc}
events:
- http:
path: /game
method: post
gameSave:
handler: src/lambda/game.save
vpc: ${self:custom.vpc}
events:
- http:
path: /game/{id}
method: put
request:
parameters:
querystrings:
name: true
score: true
paths:
id: true
gameScores:
handler: src/lambda/game.scores
vpc: ${self:custom.vpc}
events:
- http:
path: /scores
method: get
gameVerify:
handler: src/lambda/game.verify
vpc: ${self:custom.vpc}
populateData:
handler: src/lambda/data.populate
vpc: ${self:custom.vpc}
getFoodItems:
handler: src/lambda/food.getAll
vpc: ${self:custom.vpc}
events:
- http:
path: /foodItems
method: get
getRandomTrashPanda:
handler: src/lambda/trash-panda.getRandom
vpc: ${self:custom.vpc}
events:
- http:
path: /trashPanda
method: get
request:
parameters:
querystrings:
used: false
saveAction:
handler: src/lambda/action.save
environment:
PARTITION_KEY: ${self:custom.kinesis.partitionKey}
STREAM_NAME: ${self:custom.kinesis.streamName}
processAction:
handler: src/lambda/action.process
vpc: ${self:custom.vpc}
plugins:
- serverless-finch
- serverless-cloudfront-invalidate
resources:
Resources:
assetsCloudFrontDistribution:
Type: AWS::CloudFront::Distribution
Properties:
DistributionConfig:
Origins:
-
DomainName: ${self:custom.client.bucketName}.s3.amazonaws.com
Id: ${self:custom.cloudFrontDistributionId}
CustomOriginConfig:
HTTPPort: 80
HTTPSPort: 443
OriginProtocolPolicy: https-only
Enabled: true
DefaultCacheBehavior:
AllowedMethods:
- HEAD
- GET
TargetOriginId: ${self:custom.cloudFrontDistributionId}
ForwardedValues:
QueryString: 'false'
Cookies:
Forward: none
ViewerProtocolPolicy: redirect-to-https
ViewerCertificate:
CloudFrontDefaultCertificate: 'true'
Tags:
- Key: Group
Value: ${self:custom.groupName}
gameDBCluster:
Type: AWS::RDS::DBCluster
Properties:
DatabaseName: ${self:custom.database.name}
DBClusterIdentifier: trash-panda-buffet
DBSubnetGroupName:
Ref: trashPandaSubnetGroup
Engine: aurora
MasterUsername: ${self:custom.database.username}
MasterUserPassword: ${self:custom.database.password}
Tags:
- Key: Group
Value: ${self:custom.groupName}
VpcSecurityGroupIds:
- Fn::GetAtt: [ trashPandaSecurityGroup, GroupId ]
gameDBInstance:
Type: AWS::RDS::DBInstance
Properties:
DBClusterIdentifier:
Ref: gameDBCluster
DBInstanceClass: db.r4.large
Engine: aurora
Tags:
- Key: Group
Value: ${self:custom.groupName}
gameActionKinesisStream:
Type: AWS::Kinesis::Stream
Properties:
Name: ${self:custom.kinesis.streamName}
ShardCount: 1
Tags:
- Key: Group
Value: ${self:custom.groupName}
trashPandaVPC:
Type: AWS::EC2::VPC
Properties:
CidrBlock: 10.0.0.0/16
EnableDnsHostnames: true
Tags:
- Key: Name
Value: trash-panda-buffet
- Key: Group
Value: ${self:custom.groupName}
trashPandaSubnetA:
Type: AWS::EC2::Subnet
Properties:
AvailabilityZone:
Fn::Select:
- 0
- Fn::GetAZs: ""
CidrBlock: 10.0.0.0/24
Tags:
- Key: Name
Value: ${self:custom.groupName}
VpcId:
Ref: trashPandaVPC
trashPandaSubnetB:
Type: AWS::EC2::Subnet
Properties:
AvailabilityZone:
Fn::Select:
- 1
- Fn::GetAZs: ""
CidrBlock: 10.0.1.0/24
Tags:
- Key: Name
Value: ${self:custom.groupName}
VpcId:
Ref: trashPandaVPC
trashPandaSubnetGroup:
Type: AWS::RDS::DBSubnetGroup
Properties:
DBSubnetGroupName: trash-panda-subnet-group
DBSubnetGroupDescription: Subnet group for trash panda buffet
SubnetIds:
- Ref: trashPandaSubnetA
- Ref: trashPandaSubnetB
Tags:
- Key: Name
Value: ${self:custom.groupName}
trashPandaSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupName: trash-panda-sg
GroupDescription: Security Group for those trash pandas
SecurityGroupEgress:
- IpProtocol: -1
CidrIp: 0.0.0.0/0
Tags:
- Key: Name
Value: ${self:custom.groupName}
VpcId:
Ref: trashPandaVPC
trashPandaSGIngressRule:
Type: AWS::EC2::SecurityGroupIngress
Properties:
IpProtocol: -1
GroupId:
Fn::GetAtt: [ trashPandaSecurityGroup, GroupId ]
SourceSecurityGroupId:
Fn::GetAtt: [ trashPandaSecurityGroup, GroupId ]
Outputs:
cloudFrontDistributionOutput:
Value:
Ref: assetsCloudFrontDistribution