This repository has been archived by the owner on Jan 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.yaml
147 lines (129 loc) · 3.97 KB
/
template.yaml
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
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
RootStream Monologue -
serverless system-to-system messaging and RPC based on AWS Lambda, API Gateway, and SQS
Parameters:
StageName:
Type: String
Default: latest
Resources:
Monologue:
Type: AWS::ApiGatewayV2::Api
Properties:
Name: Monologue
ProtocolType: WEBSOCKET
RouteSelectionExpression: '$request.body.route'
ApiKeySelectionExpression: '$request.header.x-api-key'
Description: >
WSS API endpoint for a Monologue deployment.
See https://github.com/rootstream/monologue
Deployment:
Type: AWS::ApiGatewayV2::Deployment
DependsOn:
- DefaultRoute
- ConnectRoute
Properties:
ApiId: !Ref Monologue
Stage:
Type: AWS::ApiGatewayV2::Stage
Properties:
StageName: !Ref StageName
DeploymentId: !Ref Deployment
ApiId: !Ref Monologue
DefaultRouteSettings:
DetailedMetricsEnabled: true
DataTraceEnabled: true
LoggingLevel: INFO
DefaultRoute:
Type: AWS::ApiGatewayV2::Route
Properties:
ApiId: !Ref Monologue
RouteKey: $default
Target: !Join ['/', ['integrations', !Ref DefaultIntegration]]
DefaultIntegration:
Type: AWS::ApiGatewayV2::Integration
Properties:
ApiId: !Ref Monologue
IntegrationType: AWS_PROXY
IntegrationUri:
Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RouterFunction.Arn}/invocations
ConnectRoute:
Type: AWS::ApiGatewayV2::Route
Properties:
ApiId: !Ref Monologue
RouteKey: $connect
ApiKeyRequired: TRUE
RouteResponseSelectionExpression: $default
Target: !Join ['/', ['integrations', !Ref ConnectIntegration]]
ConnectIntegration:
Type: AWS::ApiGatewayV2::Integration
Properties:
ApiId: !Ref Monologue
IntegrationType: MOCK
RequestTemplates:
'200': '{"statusCode":200}'
TemplateSelectionExpression: '200'
ConnectIntegrationResponse:
Type: AWS::ApiGatewayV2::IntegrationResponse
Properties:
ApiId: !Ref Monologue
IntegrationId: !Ref ConnectIntegration
IntegrationResponseKey: $default
ResponseTemplates:
'200': '{"statusCode":200}'
TemplateSelectionExpression: '*'
ConnectRouteResponse:
Type: AWS::ApiGatewayV2::RouteResponse
Properties:
ApiId: !Ref Monologue
RouteResponseKey: $default
RouteId: !Ref ConnectRoute
RouterFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: router/
Handler: app.lambdaHandler
MemorySize: 256
Runtime: nodejs10.x
Policies:
- Statement:
- Effect: Allow
Action:
- 'execute-api:ManageConnections'
Resource:
- !Sub 'arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${Monologue}/*'
Environment:
Variables:
DEBUG: monologue:*
REGION: !Sub ${AWS::Region}
ENDPOINT: !Join ['', [!Ref Monologue, '.execute-api.', !Ref 'AWS::Region', '.amazonaws.com/', !Ref StageName]]
InvokePermission:
Type: AWS::Lambda::Permission
Properties:
Action: lambda:InvokeFunction
FunctionName: !Ref RouterFunction
Principal: apigateway.amazonaws.com
UsagePlan:
Type: AWS::ApiGateway::UsagePlan
Properties:
ApiStages:
- ApiId: !Ref Monologue
Stage: !Ref Stage
ApiKey:
Type: AWS::ApiGateway::ApiKey
Properties:
Enabled: true
UsagePlanKey:
Type: AWS::ApiGateway::UsagePlanKey
Properties:
KeyId: !Ref ApiKey
KeyType: API_KEY
UsagePlanId: !Ref UsagePlan
Outputs:
WebSocketURI:
Description: 'Monologue WSS Protocol URI to connect to'
Value: !Join ['', ['wss://', !Ref Monologue, '.execute-api.', !Ref 'AWS::Region', '.amazonaws.com/', !Ref 'Stage']]
ApiKeyID:
Description: 'Monologue API Key ID to access the RPC backend'
Value: !Ref ApiKey