This repository was archived by the owner on Feb 18, 2023. 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
executable file
·156 lines (148 loc) · 4.53 KB
/
serverless.yml
File metadata and controls
executable file
·156 lines (148 loc) · 4.53 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
org: drapaiton
app: drapaiton-portfolio
frameworkVersion: '2'
service: pubsub-model
package:
patterns:
- '!node_modules/**'
- '!.aws-sam/**'
- '!.serverless/**'
custom:
# This can be changed to the desired origin
# When using lambda proxy integration, you have to manually add the CORS headers to responses...
# https://github.com/serverless/serverless/issues/4681
CORS_ORIGIN: '*'
provider:
name: aws
runtime: python3.8
region: us-east-2
memorySize: 128
lambdaHashingVersion: 20201221
stage: prod
timeout: 5
logs:
websocket:
level: INFO
websocketsApiRouteSelectionExpression: $request.body.action
environment:
PRODUCTION: 1
CORS_ORIGIN: ${self:custom.CORS_ORIGIN}
WEB_SOCKET_ENDPOINT:
Fn::Join:
- ''
- - https://
- Ref: WebsocketsApi
- .execute-api.
- Ref: AWS::Region
- .amazonaws.com/
- ${self:provider.stage}
APIG_ENDPOINT:
Fn::Join:
- ''
- - https://
- Ref: ApiGatewayRestApi
- .execute-api.
- Ref: AWS::Region
- .amazonaws.com/
- ${self:provider.stage}
DYNAMODB_SOCKETS_TYPE_GSI: ${self:service}-sockets-type-gsi-${opt:stage, self:provider.stage}
DYNAMODB_SOCKETS_TABLE: ${self:service}-sockets-${opt:stage, self:provider.stage}
iam:
role:
statements:
- Effect: Allow
Action:
- "dynamodb:PutItem"
- "dynamodb:GetItem"
- "dynamodb:DeleteItem"
- "dynamodb:UpdateItem"
- "dynamodb:Scan"
Resource:
- Fn::GetAtt: [WebsocketUsersTable, Arn]
- Effect: Allow
Action:
- "execute-api:Invoke"
Resource:
- "*"
- Effect: Allow
Action:
- "execute-api:ManageConnections"
Resource:
- "arn:aws:execute-api:*:*:**/@connections/*"
functions:
auth:
handler: src/auth.handler
websocket-connect:
handler: src/web-socket.connect_handler
events:
- websocket:
route: $connect
authorizer:
name: auth
identitySource:
- "route.request.querystring.username"
websocket-disconnect:
handler: src/web-socket.disconnect_handler
events:
- websocket:
route: $disconnect
websocket-default:
handler: src/web-socket.default_handler
events:
- websocket:
route: $default
websocket-message:
handler: src/web-socket.writing_handler
events:
- websocket:
route: im_writing
endpoint-register-user:
handler: src/new_resource.register_user_handler
events: # The Events that trigger this Function
- http:
path: /register/{user}
integration: lambda
method: post
cors: false
private: false # Requires clients to add API keys values in the `x-api-key` header of their request
request:
passThrough: WHEN_NO_MATCH
parameters:
paths:
user: true
endpoint-send-message:
handler: src/new_resource.send_message_handler
events: # The Events that trigger this Function
- http:
path: /send
integration: lambda
method: post
cors: false
private: false # Requires clients to add API keys values in the `x-api-key` header of their request
request:
passThrough: WHEN_NO_MATCH
schemas:
application/json: ${file(schemas/send_message.json)}
resources:
# CloudFormation stack description
Description: >
PUB-SUB model implementation
for a simple chat webapp application
Resources:
WebsocketUsersTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: WebSocketUsers
KeySchema:
- AttributeName: username
KeyType: HASH
- AttributeName: event
KeyType: RANGE
AttributeDefinitions:
- AttributeName: username
AttributeType: S
- AttributeName: event
AttributeType: S
BillingMode: PAY_PER_REQUEST
plugins:
- serverless-python-requirements