-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtemplate.yaml
249 lines (234 loc) · 7.28 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
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# This is the SAM template that represents the architecture of your serverless application
# https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-template-basics.html
# The AWSTemplateFormatVersion identifies the capabilities of the template
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/format-version-structure.html
AWSTemplateFormatVersion: 2010-09-09
Description: >-
serverless
# Transform section specifies one or more macros that AWS CloudFormation uses to process your template
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/transform-section-structure.html
Transform:
- AWS::Serverless-2016-10-31
Globals:
Function:
Environment:
Variables:
IVS_BUCKET_NAME: !Ref IvsBucket
IVS_RECORD_CONF_ARN: !Ref IvsRecordConf
LIVE_STOP_SQS_URL: !Ref LiveStopQueue
# Resources declares the AWS resources that you want to include in the stack
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/resources-section-structure.html
Resources:
serverlessApi:
Type: AWS::Serverless::Api
Properties:
StageName: dev
Auth:
ApiKeyRequired: true
Cors:
AllowMethods: "'GET,POST,OPTIONS'"
AllowHeaders: "'content-type'"
AllowOrigin: "'*'"
createChannelFunction:
Type: AWS::Serverless::Function
Properties:
Handler: src/handlers/create-channel.handler
Runtime: nodejs16.x
Architectures:
- x86_64
MemorySize: 128
Timeout: 5
Description: A lambda to add a channel to a DynamoDB table.
Policies:
# Give Create/Read/Update/Delete Permissions to the ChannelTable
- DynamoDBCrudPolicy:
TableName: !Ref ChannelTable
- AmazonS3FullAccess
- Statement:
- Effect: Allow
Action:
- ivs:*
Resource: '*'
- Effect: Allow
Action:
- servicequotas:ListServiceQuotas
Resource: '*'
- Effect: Allow
Action:
- iam:CreateServiceLinkedRole
- iam:AttachRolePolicy
- iam:PutRolePolicy
Resource: 'arn:aws:iam::*:role/aws-service-role/ivs.amazonaws.com/AWSServiceRoleForIVSRecordToS3*'
Environment:
Variables:
# Make table name accessible as environment variable from function code during execution
CHANNEL_TABLE: !Ref ChannelTable
Events:
Api:
Type: Api
Properties:
RestApiId: !Ref serverlessApi
Path: /channel
Method: POST
stopChannelFunction:
Type: AWS::Serverless::Function
Properties:
Handler: src/handlers/stop-channel.handler
Runtime: nodejs16.x
Architectures:
- x86_64
MemorySize: 128
Timeout: 5
Description: A lambda to stop stream and delete channel. update end info to dynamodb and publish channel deleted events to SQS
Policies:
# Give Create/Read/Update/Delete Permissions to the ChannelTable
- DynamoDBCrudPolicy:
TableName: !Ref ChannelTable
- AmazonSQSFullAccess
- AmazonS3FullAccess
- Statement:
- Effect: Allow
Action:
- ivs:*
Resource: '*'
Environment:
Variables:
# Make table name accessible as environment variable from function code during execution
CHANNEL_TABLE: !Ref ChannelTable
Events:
Api:
Type: Api
Properties:
RestApiId: !Ref serverlessApi
Path: /channels/{channelName}/stop
Method: POST
getChannelFunction:
Type: AWS::Serverless::Function
Properties:
Handler: src/handlers/get-channel.handler
Runtime: nodejs16.x
Architectures:
- x86_64
MemorySize: 128
Timeout: 10
Description: A lambda to get channel from a DynamoDB table
Policies:
# Give Create/Read/Update/Delete Permissions to the ChannelTable
- DynamoDBCrudPolicy:
TableName: !Ref ChannelTable
Environment:
Variables:
# Make table name accessible as environment variable from function code during execution
CHANNEL_TABLE: !Ref ChannelTable
Events:
getChannelApi:
Type: Api
Properties:
RestApiId: !Ref serverlessApi
Path: /channels/{channelName}
Method: GET
getChannelsApi:
Type: Api
Properties:
RestApiId: !Ref serverlessApi
Path: /channels
Method: GET
proxyChannelFunction:
Type: AWS::Serverless::Function
Properties:
Handler: src/handlers/proxy-channel.handler
Runtime: nodejs16.x
Architectures:
- x86_64
MemorySize: 128
Timeout: 10
Description: A lambda to proxy channel
Policies:
# Give Create/Read/Update/Delete Permissions to the ChannelTable
- DynamoDBCrudPolicy:
TableName: !Ref ChannelTable
Environment:
Variables:
# Make table name accessible as environment variable from function code during execution
CHANNEL_TABLE: !Ref ChannelTable
Events:
getChannelApi:
Type: Api
Properties:
RestApiId: !Ref serverlessApi
Path: /channels/{channelName}/{fileName}
Method: GET
ApiKeyRequired: false
ChannelTable:
Type: AWS::Serverless::SimpleTable
Properties:
TableName: channel
PrimaryKey:
Name: channel_name
Type: String
ProvisionedThroughput:
ReadCapacityUnits: 2
WriteCapacityUnits: 2
IvsBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: "ivs-test-bucket"
IvsRecordConf:
Type: AWS::IVS::RecordingConfiguration
DependsOn: IvsBucket
Properties:
DestinationConfiguration:
S3:
BucketName: !Ref IvsBucket
Name: "ivs-recording-configuration"
ThumbnailConfiguration:
RecordingMode: 'INTERVAL'
TargetIntervalSeconds: 60
LiveStopQueue:
Type: AWS::SQS::Queue
Properties:
QueueName: "live_stop"
MessageRetentionPeriod: 60
VisibilityTimeout: 70
ApiKey:
Type: 'AWS::ApiGateway::ApiKey'
DependsOn:
- serverlessApi
Properties:
Name: serverlessApiKey
Description: Serverless API Key V1
Enabled: true
StageKeys:
- RestApiId: !Ref serverlessApi
StageName: dev
UsagePlan:
Type: 'AWS::ApiGateway::UsagePlan'
DependsOn:
- serverlessApi
Properties:
ApiStages:
- ApiId: !Ref serverlessApi
Stage: dev
Description: serverlessApi usage plan
Quota:
Limit: 5000
Period: MONTH
Throttle:
BurstLimit: 10
RateLimit: 10
UsagePlanName: Plan_serverlessApi
ApiUsagePlanKey:
Type: "AWS::ApiGateway::UsagePlanKey"
DependsOn:
- serverlessApi
Properties:
KeyId: !Ref ApiKey
KeyType: API_KEY
UsagePlanId: !Ref UsagePlan
Outputs:
WebEndpoint:
Description: "API Gateway endpoint URL for dev"
Value: !Sub "https://${serverlessApi}.execute-api.${AWS::Region}.amazonaws.com/dev/"
ApiKey:
Description: "API Key"
Value: !Ref ApiKey