-
Notifications
You must be signed in to change notification settings - Fork 35
/
video-website-solution.yml
526 lines (525 loc) · 15.3 KB
/
video-website-solution.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
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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
ROSTemplateFormatVersion: '2015-09-01'
Description:
zh-cn: 创建双可用区ECS实例、OSS存储桶、ALB负载均衡、MNS队列,配置媒体处理与视频上传服务,实现视频网站的存储与CDN分发。
en: Create dual availability zone ECS instances, OSS buckets, ALB load balancers,
and MNS queues, configure media processing and video upload services, to implement
storage for the video website and CDN distribution.
Parameters:
BucketNameScr:
Type: String
Label:
en: Source Bucket Name
zh-cn: 源存储空间名称
Description:
en: The name must be 3 to 63 bytes in length, The name must start and end with
a lowercase letter or digit.The name can contain only lowercase letters, digits,
and hyphens (-).;<br><b>note:<font color='blue'>A bucket name must be globally
unique within OSS. Bucket names cannot be changed after the bucket is created.</b></font>
zh-cn: 长度为3~63个字符,必须以小写字母或数字开头和结尾,可以包含小写字母、数字和连字符(-);<br><b>注:<font color='blue'>需要全网唯一性,已经存在的不能在创建。</b></font>
AssociationProperty: AutoCompleteInput
AssociationPropertyMetadata:
Length: 5
Prefix: vod-bucket-src-
CharacterClasses:
- Class: lowercase
min: 1
BucketNameTarget:
Type: String
Label:
en: Target Bucket Name
zh-cn: 目标存储空间名称
Description:
en: The name must be 3 to 63 bytes in length, The name must start and end with
a lowercase letter or digit.The name can contain only lowercase letters, digits,
and hyphens (-).;<br><b>note:<font color='blue'>A bucket name must be globally
unique within OSS. Bucket names cannot be changed after the bucket is created.</b></font>
zh-cn: 长度为3~63个字符,必须以小写字母或数字开头和结尾,可以包含小写字母、数字和连字符(-);<br><b>注:<font color='blue'>需要全网唯一性,已经存在的不能在创建。</b></font>
AssociationProperty: AutoCompleteInput
AssociationPropertyMetadata:
Length: 5
Prefix: vod-bucket-target-
CharacterClasses:
- Class: lowercase
min: 1
Zone1:
Type: String
Label:
en: VSwitch Availability Zone1
zh-cn: 交换机可用区1
AssociationProperty: ALIYUN::ECS::Instance::ZoneId
AssociationPropertyMetadata:
AutoSelectFirst: true
ExclusiveTo:
- Zone2
Zone2:
Type: String
Label:
en: VSwitch Availability Zone2
zh-cn: 交换机可用区2
AssociationProperty: ALIYUN::ECS::Instance::ZoneId
AssociationPropertyMetadata:
ExclusiveTo:
- Zone1
EcsInstanceType1:
Type: String
Label:
en: ECS Instance Type 1
zh-cn: ECS实例类型1
AssociationProperty: ALIYUN::ECS::Instance::InstanceType
AssociationPropertyMetadata:
InstanceChargeType: PostPaid
SystemDiskCategory: cloud_essd
ZoneId: ${Zone1}
EcsInstanceType2:
Type: String
Label:
en: ECS Instance Type 2
zh-cn: ECS实例类型2
AssociationProperty: ALIYUN::ECS::Instance::InstanceType
AssociationPropertyMetadata:
InstanceChargeType: PostPaid
SystemDiskCategory: cloud_essd
ZoneId: ${Zone2}
InstancePassword:
Type: String
Label:
en: Instance Password
zh-cn: 实例密码
Description:
en: Server login password, Length 8-30, must contain three(Capital letters,
lowercase letters, numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol
in)
zh-cn: 服务器登录密码,长度8-30,必须包含三项(大写字母、小写字母、数字、 ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ 中的特殊符号)
ConstraintDescription:
en: Length 8-30, must contain three(Capital letters, lowercase letters, numbers,
()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol in)
zh-cn: 长度8-30,必须包含三项(大写字母、小写字母、数字、 ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ 中的特殊符号)
AssociationProperty: ALIYUN::ECS::Instance::Password
AllowedPattern: ^[a-zA-Z0-9-\(\)\`\~\!\@\#\$\%\^\&\*\_\-\+\=\|\{\}\[\]\:\;\<\>\,\.\?\/]*$
MinLength: 8
MaxLength: 30
NoEcho: true
CommonName:
Type: String
Default: video-website
Resources:
AutoEnableOSS:
Type: ALIYUN::ROS::AutoEnableService
Properties:
ServiceName: OSS
AutoEnableMNS:
Type: ALIYUN::ROS::AutoEnableService
Properties:
ServiceName: MNS
EcsVpc:
Type: ALIYUN::ECS::VPC
Properties:
VpcName:
Fn::Sub: ${CommonName}-vpc
CidrBlock: 192.168.0.0/16
EcsVSwitch1:
Type: ALIYUN::ECS::VSwitch
Properties:
ZoneId:
Ref: Zone1
VpcId:
Ref: EcsVpc
VSwitchName:
Fn::Sub: ${CommonName}-vsw-001
CidrBlock: 192.168.1.0/24
EcsVSwitch2:
Type: ALIYUN::ECS::VSwitch
Properties:
ZoneId:
Ref: Zone2
VpcId:
Ref: EcsVpc
VSwitchName:
Fn::Sub: ${CommonName}-vsw-002
CidrBlock: 192.168.2.0/24
EcsSecurityGroup:
Type: ALIYUN::ECS::SecurityGroup
Properties:
VpcId:
Ref: EcsVpc
SecurityGroupName:
Fn::Sub: ${CommonName}-sg
SecurityGroupIngress:
- PortRange: 8000/8000
Priority: 1
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
NicType: internet
RoleForEcs:
Type: ALIYUN::RAM::Role
Properties:
RoleName:
Fn::Sub: ${CommonName}-${ALIYUN::StackId}-role
Description: RAMRoleForECS
AssumeRolePolicyDocument:
Version: '1'
Statement:
- Action: sts:AssumeRole
Effect: Allow
Principal:
Service:
- ecs.aliyuncs.com
MaxSessionDuration: 3600
DeletionForce: true
PolicyAttachments:
System:
- AliyunSTSAssumeRoleAccess
VodUploadRoleTestRole:
Type: ALIYUN::RAM::Role
Properties:
RoleName:
Fn::Sub: ${CommonName}-${ALIYUN::StackId}-VodUploadRole
Description: VodUploadRoleTest
AssumeRolePolicyDocument:
Statement:
- Action: sts:AssumeRole
Effect: Allow
Principal:
RAM:
- Fn::Sub: acs:ram::${ALIYUN::TenantId}:root
Version: '1'
MaxSessionDuration: 3600
DeletionForce: true
PolicyAttachments:
System:
- AliyunSTSAssumeRoleAccess
- AliyunVODUploadAuth
EcsInstanceGroup1:
Type: ALIYUN::ECS::InstanceGroup
Properties:
ZoneId:
Ref: Zone1
VpcId:
Ref: EcsVpc
VSwitchId:
Ref: EcsVSwitch1
SecurityGroupId:
Ref: EcsSecurityGroup
ImageId: aliyun_3_9_x64_20G_alibase_20231219.vhd
IoOptimized: optimized
SystemDiskCategory: cloud_essd
InternetMaxBandwidthOut: 5
SystemDiskSize: 40
MaxAmount: 1
InstanceType:
Ref: EcsInstanceType1
Password:
Ref: InstancePassword
InstanceName:
Fn::Sub: ${CommonName}-ecs1
RamRoleName:
Ref: RoleForEcs
EcsInstanceGroup2:
Type: ALIYUN::ECS::InstanceGroup
Properties:
ZoneId:
Ref: Zone2
VpcId:
Ref: EcsVpc
VSwitchId:
Ref: EcsVSwitch2
SecurityGroupId:
Ref: EcsSecurityGroup
ImageId: aliyun_3_9_x64_20G_alibase_20231219.vhd
IoOptimized: optimized
SystemDiskCategory: cloud_essd
InternetMaxBandwidthOut: 5
SystemDiskSize: 40
MaxAmount: 1
InstanceType:
Ref: EcsInstanceType2
Password:
Ref: InstancePassword
InstanceName:
Fn::Sub: ${CommonName}-ecs2
RamRoleName:
Ref: RoleForEcs
AlbLoadBalancer:
Type: ALIYUN::ALB::LoadBalancer
Properties:
VpcId:
Ref: EcsVpc
LoadBalancerName:
Fn::Sub: ${CommonName}-alb
LoadBalancerEdition: Basic
LoadBalancerBillingConfig:
PayType: PostPay
AddressType: Internet
AddressAllocatedMode: Fixed
ZoneMappings:
- ZoneId:
Ref: Zone1
VSwitchId:
Ref: EcsVSwitch1
- ZoneId:
Ref: Zone2
VSwitchId:
Ref: EcsVSwitch2
AlbServerGroup:
Type: ALIYUN::ALB::ServerGroup
Properties:
VpcId:
Ref: EcsVpc
HealthCheckConfig:
HealthCheckEnabled: true
HealthCheckPath: /
HealthCheckCodes:
- http_2xx
- http_3xx
HealthCheckProtocol: HTTP
ServerGroupName:
Fn::Sub: ${CommonName}-server-group
StickySessionConfig:
StickySessionEnabled: false
ServerAttachment:
Type: ALIYUN::ALB::BackendServerAttachment
Properties:
ServerGroupId:
Ref: AlbServerGroup
Servers:
- ServerType: Ecs
ServerId:
Ref: EcsInstanceGroup1
Port: 8000
Weight: 100
- ServerType: Ecs
ServerId:
Ref: EcsInstanceGroup2
Port: 8000
Weight: 100
AlbListener:
Type: ALIYUN::ALB::Listener
Properties:
ListenerPort: 8000
DefaultActions:
- Type: ForwardGroup
ForwardGroupConfig:
ServerGroupTuples:
- ServerGroupId:
Ref: AlbServerGroup
LoadBalancerId:
Ref: AlbLoadBalancer
ListenerProtocol: HTTP
OssBucketScr:
Type: ALIYUN::OSS::Bucket
DependsOn: AutoEnableOSS
Properties:
BucketName:
Ref: BucketNameScr
StorageClass: Standard
DeletionForce: true
OssBucketTarget:
Type: ALIYUN::OSS::Bucket
DependsOn: AutoEnableOSS
Properties:
BucketName:
Ref: BucketNameTarget
StorageClass: Standard
DeletionForce: true
VideoUploadService:
Type: ALIYUN::ECS::RunCommand
Properties:
InstanceIds:
- Ref: EcsInstanceGroup1
- Ref: EcsInstanceGroup2
Sync: true
Type: RunShellScript
Timeout: 300
CommandContent:
Fn::Sub: |
#!/bin/bash
wget https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20230830/qhwb/server.zip
yum install unzip -y
unzip server.zip
cd server
pip3 install --upgrade pip
pip3 install -r requirements.txt
pip3 install uwsgi==2.0.22
sed -i "s/socket=127.0.0.1:5000/http=0.0.0.0:8000/g" uwsgi.ini
export ECS_RAM_ROLE=${RoleForEcs}
export ROLE_ARN=${VodUploadRoleTestRole.Arn}
nohup uwsgi uwsgi.ini > output.log 2>&1 &
Queue:
Type: ALIYUN::MNS::Queue
DependsOn: AutoEnableMNS
Properties:
QueueName:
Fn::Sub: ${CommonName}-mns-queue
VodStorage:
Type: ALIYUN::VOD::Storage
DependsOn: AliyunVODDefaultRole
Properties:
StorageType: user_oss_bucket
StorageLocation:
Fn::Sub: ${OssBucketScr.DomainName}
DefaultUpload: true
MessageCallback:
Type: ALIYUN::VOD::MessageCallback
Properties:
CallbackType: MNS
MnsEndpoint:
Fn::Sub: http://${ALIYUN::TenantId}.mns.${ALIYUN::Region}.aliyuncs.com/
MnsQueueName:
Fn::Sub: ${Queue.QueueName}
EventTypeList: FileUploadComplete
AliyunFCServerlessDevsRole:
Type: ALIYUN::RAM::Role
Properties:
RoleName: AliyunFCServerlessDevsRole
Description: 应用中心需要您的角色中包含应用所需策略,推荐创建并使用系统默认角色 AliyunFCServerlessDevsRole。
AssumeRolePolicyDocument:
Version: '1'
Statement:
- Action: sts:AssumeRole
Effect: Allow
Principal:
Service:
- fc.aliyuncs.com
MaxSessionDuration: 3600
IgnoreExisting: true
DeletionForce: true
PolicyAttachments:
System:
- AliyunNASFullAccess
- AliyunFCFullAccess
- AliyunFCServerlessDevsRolePolicy
- AliyunOSSReadOnlyAccess
- AliyunECSReadOnlyAccess
- AliyunVPCReadOnlyAccess
- AliyunLogReadOnlyAccess
AliyunFcRole:
Type: ALIYUN::RAM::Role
Properties:
RoleName: AliyunFcDefaultRole
Description: Service Role for FC to operate other resource
AssumeRolePolicyDocument:
Version: '1'
Statement:
- Action: sts:AssumeRole
Effect: Allow
Principal:
Service:
- fc.aliyuncs.com
MaxSessionDuration: 3600
DeletionForce: true
IgnoreExisting: true
PolicyAttachments:
System:
- AliyunFCDefaultRolePolicy
- AliyunOSSFullAccess
Application:
Type: ALIYUN::FC::Application
Properties:
Name:
Fn::Sub: ffmpeg-app-${ALIYUN::StackId}
RoleARN:
Fn::GetAtt:
- AliyunFCServerlessDevsRole
- Arn
Parameters:
serviceName:
Fn::Sub: ffmpeg-app-${ALIYUN::StackId}
functionName:
Fn::Sub: ffmpeg-app-${ALIYUN::StackId}
region:
Ref: ALIYUN::Region
roleArn:
Fn::GetAtt:
- AliyunFcRole
- Arn
Template: ffmpeg-app
AutoDeploy: true
FcTrigger:
Type: ALIYUN::FC::Trigger
Properties:
ServiceName:
Fn::Sub: ffmpeg-app-${ALIYUN::StackId}
FunctionName: VideoWatermark
TriggerName: fc-trigger
TriggerType: eventbridge
TriggerConfig:
triggerEnable: true
asyncInvocationType: true
eventSinkConfig:
deliveryOption:
mode: event-streaming
eventSchema: RawData
eventSourceConfig:
eventSourceType: MNS
eventSourceParameters:
sourceMNSParameters:
RegionId:
Ref: ALIYUN::Region
QueueName:
Fn::Sub: ${Queue.QueueName}
eventRuleFilterPattern: '{}'
runOptions:
mode: event-streaming
errorsTolerance: ALL
retryStrategy:
pushRetryStrategy: EXPONENTIAL_DECAY_RETRY
deadLetterQueue: null
DependsOn:
- Application
- MessageCallback
- VodStorage
AliyunVODDefaultRole:
Type: ALIYUN::RAM::Role
Properties:
RoleName: AliyunVODDefaultRole
Description: VOD默认使用此角色来访问您在其他云产品中的资源。
AssumeRolePolicyDocument:
Version: '1'
Statement:
- Action: 'sts:AssumeRole'
Effect: Allow
Principal:
Service:
- vod.aliyuncs.com
MaxSessionDuration: 3600
IgnoreExisting: true
DeletionForce: true
PolicyAttachments:
System:
- AliyunVODRolePolicy
Outputs:
VideoUrl:
Description:
en: Video upload address.
zh-cn: 视频上传地址。
Value:
Fn::Sub:
- http://${AlbDnsName}:8000
- AlbDnsName:
Fn::GetAtt:
- AlbLoadBalancer
- DNSName
Metadata:
ALIYUN::ROS::Interface:
ParameterGroups:
- Parameters:
- BucketNameScr
- BucketNameTarget
Label:
default:
en: OSS bucket
zh-cn: 对象存储OSS配置
- Parameters:
- Zone1
- Zone2
- EcsInstanceType1
- EcsInstanceType2
- InstancePassword
Label:
default:
en: ECS configure
zh-cn: 云服务器ECS配置
TemplateTags:
- acs:technical-solution:internet-application-development:视频网站的存储与媒体处理方案-tech_solu_06
Hidden:
- CommonName