generated from neverendingqs/node-github-template
-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathserverless.yml
105 lines (91 loc) · 3.03 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
service: websocket-example
plugins:
- serverless-plugin-common-excludes
- serverless-plugin-include-dependencies
- '@anttiviljami/serverless-stack-output'
custom:
output:
file: ./client/data.json
stage: ${opt:stage, 'dev'}
provider:
name: aws
# If you use a lower runtime (e.g. nodejs8.10), you have to bundle your own
# 'aws-sdk', as ApiGatewayManagementApi was not introduced until
# [email protected]. See https://github.com/aws/aws-sdk-js/issues/2520#issuecomment-476723105
# for details.
runtime: nodejs10.x
environment:
APIG_ENDPOINT:
Fn::Join:
- ''
- - Ref: WebsocketsApi
- .execute-api.
- Ref: AWS::Region
- .amazonaws.com/
- ${self:custom.stage}
CONNECTIONS_TABLE:
Ref: ConnectionsTable
iamRoleStatements:
- Effect: Allow
Action:
- dynamodb:DeleteItem
- dynamodb:GetItem
- dynamodb:Scan
- dynamodb:PutItem
Resource:
Fn::GetAtt:
- ConnectionsTable
- Arn
functions:
authorizer:
handler: src/authorizer.handler
broadcast:
handler: src/broadcast.handler
# See https://serverless.com/framework/docs/providers/aws/events/websocket/
# for full details
websocket:
handler: src/websocket.handler
events:
- websocket:
# Handles new connection requests
route: $connect
# Only the '$connect' route supports an authorizer. The other routes
# are secured via the connection ID and therefore it should be handled
# like a session ID.
authorizer:
name: authorizer
# See https://serverless.com/framework/docs/providers/aws/events/websocket#using-authorizers
# and https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigatewayv2-authorizer.html#cfn-apigatewayv2-authorizer-identitysource
# for more details on identitySource.
# See https://docs.aws.amazon.com/apigateway/latest/developerguide/request-response-data-mappings.html
# for more details on API Gateway mappings.
identitySource:
- 'route.request.header.X-Forwarded-Proto'
- websocket:
# Route messages here if '$request.body.action' is 'routeA'.
# You can adjust which property to use for routing by adjusting
# 'websocketsApiRouteSelectionExpression'.
route: routeA
- websocket:
# Handles all unrouted messages
route: $default
- websocket:
# Handles disconnect messages
route: $disconnect
resources:
Resources:
ConnectionsTable:
Type: AWS::DynamoDB::Table
Properties:
AttributeDefinitions:
- AttributeName: connectionId
AttributeType: S
BillingMode: PAY_PER_REQUEST
KeySchema:
- AttributeName: connectionId
KeyType: HASH
SSESpecification:
SSEEnabled: true
TimeToLiveSpecification:
AttributeName: ttl
Enabled: true