-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.yaml
194 lines (168 loc) · 5.11 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
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
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
########## API Gateway WebSocket Resources ############
Api:
Type: AWS::ApiGatewayV2::Api
Properties:
Name: Api
ProtocolType: WEBSOCKET
RouteSelectionExpression: $request.body.action
Stage:
Type: AWS::ApiGatewayV2::Stage
Properties:
StageName: v1
Description: Version 1 'stage'
DeploymentId: !Ref Deployment
ApiId: !Ref Api
Deployment:
Type: AWS::ApiGatewayV2::Deployment
DependsOn:
- ConnectRoute
Properties:
ApiId: !Ref Api
# Role for APIGW Logging
ApiGatewayLoggingRole:
Type: AWS::IAM::Role
Properties:
Description: Allows APIGateway to write to cloudwatch logs.
AssumeRolePolicyDocument:
Statement:
- Action: sts:AssumeRole
Effect: Allow
Principal:
Service: apigateway.amazonaws.com
Version: "2012-10-17"
MaxSessionDuration: 3600
Path: '/'
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AmazonAPIGatewayPushToCloudWatchLogs
ApiGatewayLoggingRoleAccount:
Type: AWS::ApiGateway::Account
Properties:
CloudWatchRoleArn: !GetAtt ApiGatewayLoggingRole.Arn
########## Authorizer Function and APIGW Config ############
Auth:
Type: AWS::ApiGatewayV2::Authorizer
Properties:
Name: Websocket-Authorizer
ApiId: !Ref Api
AuthorizerType: REQUEST
AuthorizerUri:
Fn::Sub:
arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${AuthFunction.Arn}/invocations
IdentitySource:
- "route.request.querystring.token"
AuthFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: auth/
Handler: bootstrap # note, this is the name of the executable output from the Makefile.
Runtime: provided.al2
Architectures: [ arm64 ]
Policies:
- AWSLambdaBasicExecutionRole
Metadata:
BuildMethod: makefile
AuthorizerFunctionPermission:
Type: AWS::Lambda::Permission
DependsOn:
- Api
- AuthFunction
Properties:
Action: lambda:InvokeFunction
FunctionName: !Ref AuthFunction
Principal: apigateway.amazonaws.com
########## Connect Route ($connect) Function and APIGW Config ############
ConnectFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: connect/
Handler: bootstrap # note, this is the name of the executable output from the Makefile.
Runtime: provided.al2
Architectures: [ arm64 ]
Policies:
- AWSLambdaBasicExecutionRole
Metadata:
BuildMethod: makefile
ConnectRoute:
Type: AWS::ApiGatewayV2::Route
Properties:
ApiId: !Ref Api
RouteKey: "$connect"
AuthorizationType: CUSTOM
OperationName: connect
AuthorizerId: !Ref Auth
Target: !Join
- '/'
- - 'integrations'
- !Ref ConnectLambdaIntegration
ConnectFunctionPermission:
Type: AWS::Lambda::Permission
DependsOn:
- Api
- ConnectFunction
Properties:
Action: lambda:InvokeFunction
FunctionName: !Ref ConnectFunction
Principal: apigateway.amazonaws.com
ConnectLambdaIntegration:
Type: AWS::ApiGatewayV2::Integration
Properties:
ApiId: !Ref Api
Description: Connect Integration
IntegrationType: AWS_PROXY
IntegrationUri:
Fn::Sub:
arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ConnectFunction.Arn}/invocations
########## Default Route ($default) Function and APIGW Config ############
DefaultFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: default/
Handler: bootstrap # note, this is the name of the executable output from the Makefile.
Runtime: provided.al2
Architectures: [ arm64 ]
Policies:
- AWSLambdaBasicExecutionRole
Metadata:
BuildMethod: makefile
DefaultRoute:
Type: AWS::ApiGatewayV2::Route
Properties:
ApiId: !Ref Api
RouteKey: "$default"
Target: !Join
- '/'
- - 'integrations'
- !Ref DefaultLambdaIntegration
DefaultFunctionPermission:
Type: AWS::Lambda::Permission
DependsOn:
- Api
- DefaultFunction
Properties:
Action: lambda:InvokeFunction
FunctionName: !Ref DefaultFunction
Principal: apigateway.amazonaws.com
DefaultLambdaIntegration:
Type: AWS::ApiGatewayV2::Integration
Properties:
ApiId: !Ref Api
Description: Default Integration
IntegrationType: AWS_PROXY
IntegrationUri:
Fn::Sub:
arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${DefaultFunction.Arn}/invocations
DefaultRouteResponse:
Type: AWS::ApiGatewayV2::RouteResponse
Properties:
RouteId: !Ref DefaultRoute
ApiId: !Ref Api
RouteResponseKey: "$default"
DefaultIntegrationResponse:
Type: AWS::ApiGatewayV2::IntegrationResponse
Properties:
IntegrationId: !Ref DefaultLambdaIntegration
IntegrationResponseKey: "$default"
ApiId: !Ref Api