This repository was archived by the owner on Nov 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserverless.yml
More file actions
221 lines (213 loc) · 7.48 KB
/
serverless.yml
File metadata and controls
221 lines (213 loc) · 7.48 KB
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
service: 'casual-apiary-aws'
org: casualos
app: casual-apiary
frameworkVersion: '2'
# Setup webpack
custom:
webpack:
webpackConfig: './webpack.config.js'
includeModules: true
serverless-offline:
httpPort: 4000
websocketPort: 4001
lambdaPort: 4002
dynamodb:
stages:
- dev
start:
migrate: true
s3:
host: localhost
directory: ./.s3
cors: ./s3-cors.xml
allowMismatchedSignatures: true
messagesBucket: 'aux-messages-bucket-${opt:stage}'
atomsTable: 'AtomsTable-${opt:stage}'
connectionsTable: 'ConnectionsTable-${opt:stage}'
namespaceConnectionsTable: 'NamespaceConnectionsTable-${opt:stage}'
# Add the serverless-webpack plugin
plugins: [
'serverless-webpack',
# 'serverless-dynamodb-local',
'serverless-s3-local',
'serverless-offline',
]
provider:
name: aws
runtime: nodejs12.x
profile: casualos
apiGateway:
shouldStartNameWithService: true
minimumCompressionSize: 1024
environment:
REDIS_HOST: '${env:REDIS_HOST}'
REDIS_PORT: '${env:REDIS_PORT}'
REDIS_PASS: '${env:REDIS_PASS}'
REDIS_TLS: '${env:REDIS_TLS}'
USE_REDIS: '${env:USE_REDIS}'
REDIS_NAMESPACE: '${opt:stage}'
MAX_REDIS_BATCH_SIZE: '${env:MAX_REDIS_BATCH_SIZE}'
ATOMS_TABLE: '${self:custom.atomsTable}'
CONNECTIONS_TABLE: '${self:custom.connectionsTable}'
NAMESPACE_CONNECTIONS_TABLE: '${self:custom.namespaceConnectionsTable}'
WEBSOCKET_URL: '${env:WEBSOCKET_URL}'
iamRoleStatements:
- Effect: Allow
Action:
- dynamodb:BatchGetItem
- dynamodb:BatchWriteItem
- dynamodb:DeleteItem
- dynamodb:GetItem
- dynamodb:PutItem
- dynamodb:Query
- dynamodb:Scan
- dynamodb:UpdateItem
Resource: 'arn:aws:dynamodb:${opt:region, self:provider.region}:*:table/${self:custom.atomsTable}'
- Effect: Allow
Action:
- dynamodb:BatchGetItem
- dynamodb:BatchWriteItem
- dynamodb:DeleteItem
- dynamodb:GetItem
- dynamodb:PutItem
- dynamodb:Query
- dynamodb:Scan
- dynamodb:UpdateItem
Resource: 'arn:aws:dynamodb:${opt:region, self:provider.region}:*:table/${self:custom.connectionsTable}'
- Effect: Allow
Action:
- dynamodb:BatchGetItem
- dynamodb:BatchWriteItem
- dynamodb:DeleteItem
- dynamodb:GetItem
- dynamodb:PutItem
- dynamodb:Query
- dynamodb:Scan
- dynamodb:UpdateItem
Resource: 'arn:aws:dynamodb:${opt:region, self:provider.region}:*:table/NamespaceConnectionsTable-${opt:stage}'
- Effect: Allow
Action:
- dynamodb:BatchGetItem
- dynamodb:BatchWriteItem
- dynamodb:DeleteItem
- dynamodb:GetItem
- dynamodb:PutItem
- dynamodb:Query
- dynamodb:Scan
- dynamodb:UpdateItem
Resource: 'arn:aws:dynamodb:${opt:region, self:provider.region}:*:table/NamespaceConnectionsTable-${opt:stage}/index/ConnectionIdAndNamespaceIndex'
- Effect: Allow
Action:
- s3:PutObject
- s3:GetObject
- s3:DeleteObject
- s3:PutObjectAcl
Resource: 'arn:aws:s3:::${self:custom.messagesBucket}/*'
functions:
connect:
handler: handler.connect
events:
- websocket:
route: $connect
disconnect:
handler: handler.disconnect
events:
- websocket:
route: $disconnect
message:
handler: handler.message
environment:
MESSAGES_BUCKET: '${self:custom.messagesBucket}'
events:
- websocket:
route: $default
webhook:
handler: handler.webhook
environment:
MESSAGES_BUCKET: '${self:custom.messagesBucket}'
events:
- http:
path: webhook
method: ANY
dataPortal:
handler: handler.instData
environment:
MESSAGES_BUCKET: '${self:custom.messagesBucket}'
events:
- http:
path: instData
method: GET
resources:
Resources:
# A DynamoDB table that groups atoms by namespace
AtomsTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: '${self:custom.atomsTable}'
BillingMode: PAY_PER_REQUEST
AttributeDefinitions:
- AttributeName: namespace
AttributeType: S
- AttributeName: atomHash
AttributeType: S
KeySchema:
- AttributeName: namespace
KeyType: HASH
- AttributeName: atomHash
KeyType: RANGE
# A DynamoDB table that stores connections
ConnectionsTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: '${self:custom.connectionsTable}'
BillingMode: PAY_PER_REQUEST
AttributeDefinitions:
- AttributeName: connectionId
AttributeType: S
KeySchema:
- AttributeName: connectionId
KeyType: HASH
# A DynamoDB table that groups connections by namespace
NamespaceConnectionsTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: '${self:custom.namespaceConnectionsTable}'
BillingMode: PAY_PER_REQUEST
AttributeDefinitions:
- AttributeName: namespace
AttributeType: S
- AttributeName: connectionId
AttributeType: S
KeySchema:
- AttributeName: namespace
KeyType: HASH
- AttributeName: connectionId
KeyType: RANGE
GlobalSecondaryIndexes:
- IndexName: ConnectionIdAndNamespaceIndex
KeySchema:
- AttributeName: connectionId
KeyType: HASH
- AttributeName: namespace
KeyType: RANGE
Projection:
ProjectionType: ALL
# A S3 bucket that is used to handle large messages (larger than 128KB)
MessagesBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: '${self:custom.messagesBucket}'
AccessControl: 'PublicRead'
LifecycleConfiguration:
Rules:
- Id: 'CleanupRule'
Prefix: ''
Status: Enabled
ExpirationInDays: 1
CorsConfiguration:
CorsRules:
- Id: 'AllowReadWriteCorsRule'
AllowedMethods: ['GET', 'PUT']
AllowedOrigins: ['*']
AllowedHeaders: ['*']
MaxAge: '3600'