-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvideo-on-demand-on-aws.template
More file actions
1701 lines (1627 loc) · 55.8 KB
/
video-on-demand-on-aws.template
File metadata and controls
1701 lines (1627 loc) · 55.8 KB
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
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Description: "(SO0021) - Video On Demand workflow with AWS Step Functions, MediaConvert, MediaPackage, S3, CloudFront and DynamoDB. Version v5.2.0"
Parameters:
AdminEmail:
Description: Email address for SNS notifications (subscribed users will receive ingest, publishing, and error notifications)
Type: String
AllowedPattern: "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$"
WorkflowTrigger:
Description: How the workflow will be triggered (source video upload to S3 or source metadata file upload)
Type: String
Default: VideoFile
AllowedValues:
- VideoFile
- MetadataFile
Glacier:
Description: If enabled, source assets will be tagged for archiving to Glacier or Glacier Deep Archive once the workflow is complete
Type: String
Default: DISABLED
AllowedValues:
- DISABLED
- GLACIER
- DEEP_ARCHIVE
FrameCapture:
Description: If enabled, frame capture is added to the job submitted to MediaConvert
Type: String
Default: No
AllowedValues:
- Yes
- No
EnableMediaPackage:
Description: If enabled, MediaPackage VOD will be included in the workflow
Type: String
Default: No
AllowedValues:
- Yes
- No
EnableSns:
Description: Enable Ingest and Publish email notifications, error messages are not afeected by this parameter.
Type: String
Default: Yes
AllowedValues:
- Yes
- No
EnableSqs:
Description: Publish the workflow results to an SQS queue to injest upstream
Type: String
Default: Yes
AllowedValues:
- Yes
- No
AcceleratedTranscoding:
Description: Enable accelerated transcoding in AWS Elemental MediaConvert. PREFERRED will only use acceleration if the input files is supported. ENABLED accleration is applied to all files (this will fail for unsupported file types) see MediaConvert Documentation for more detail https://docs.aws.amazon.com/mediaconvert/latest/ug/accelerated-transcoding.html
Type: String
Default: PREFERRED
AllowedValues:
- ENABLED
- DISABLED
- PREFERRED
Metadata:
AWS::CloudFormation::Interface:
ParameterGroups:
-
Label:
default: "Workflow"
Parameters:
- AdminEmail
- WorkflowTrigger
- Glacier
- EnableSns
- EnableSqs
-
Label:
default: "AWS Elemental MediaConvert"
Parameters:
- FrameCapture
- AcceleratedTranscoding
-
Label:
default: "AWS Elemental MediaPackage"
Parameters:
- EnableMediaPackage
ParameterLabels:
AdminEmail:
default: Notification email address
Glacier:
default: Archive source content
WorkflowTrigger:
default: Workflow trigger
FrameCapture:
default: Enable Frame Capture
EnableMediaPackage:
default: Enable MediaPackage
AcceleratedTranscoding:
default: Accelerated Transcoding
EnableSns:
default: Enable SNS Notifications
EnableSqs:
default: Enable SQS Messaging
Mappings:
SourceCode:
General:
S3Bucket: "solutions"
KeyPrefix: "video-on-demand-on-aws/v5.2.0"
AnonymousData:
SendAnonymousData:
Data: Yes
Conditions:
Metrics: !Equals [!FindInMap [AnonymousData, SendAnonymousData, Data], Yes]
IsMediaPackageEnabled: !Equals [!Ref EnableMediaPackage, Yes]
Resources:
CustomResourceRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- sts:AssumeRole
Path: "/"
Policies:
- PolicyName: !Sub "${AWS::StackName}-custom-resource"
PolicyDocument:
Statement:
- Effect: Allow
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Resource:
- !Sub "arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/*"
- Effect: Allow
Action:
- s3:PutBucketNotification
- s3:PutObject
- s3:PutObjectAcl
Resource:
- !GetAtt Source.Arn
- Effect: Allow
Action:
- mediaconvert:CreatePreset
- mediaconvert:CreateJobTemplate
- mediaconvert:DeletePreset
- mediaconvert:DeleteJobTemplate
- mediaconvert:DescribeEndpoints
- mediaconvert:ListJobTemplates
Resource:
- !Sub "arn:${AWS::Partition}:mediaconvert:${AWS::Region}:${AWS::AccountId}:*"
- Effect: Allow
Action:
- mediapackage-vod:DeleteAsset
- mediapackage-vod:DeletePackagingConfiguration
Resource:
- !Sub "arn:${AWS::Partition}:mediapackage-vod:${AWS::Region}:${AWS::AccountId}:assets/*"
- !Sub "arn:${AWS::Partition}:mediapackage-vod:${AWS::Region}:${AWS::AccountId}:packaging-configurations/packaging-config-*"
- Effect: Allow
Action:
- mediapackage-vod:DescribePackagingGroup
- mediapackage-vod:DeletePackagingGroup
Resource:
- !Sub "arn:${AWS::Partition}:mediapackage-vod:${AWS::Region}:${AWS::AccountId}:packaging-groups/${AWS::StackName}-packaging-group"
- Effect: Allow
Action:
- mediapackage-vod:CreatePackagingConfiguration
- mediapackage-vod:CreatePackagingGroup
- mediapackage-vod:ListAssets
- mediapackage-vod:ListPackagingConfigurations
- mediapackage-vod:ListPackagingGroups
Resource: "*"
- Effect: Allow
Action:
- cloudfront:GetDistributionConfig
- cloudfront:UpdateDistribution
Resource:
- !Sub "arn:${AWS::Partition}:cloudfront::${AWS::AccountId}:distribution/${CloudFront}"
Metadata:
cfn_nag:
rules_to_suppress:
- id: W11
reason: "* is required to create CloudWatch logs and interact with MediaConvert / MediaPackage actions that do not support resource level permissions"
- id: W76
reason: "All policies are required by the custom resource."
StepFunctionsServiceRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- !Sub "states.${AWS::Region}.amazonaws.com"
Action:
- sts:AssumeRole
Policies:
- PolicyName: !Sub "${AWS::StackName}-stepfunctions-service-role"
PolicyDocument:
Statement:
- Effect: Allow
Action:
- lambda:InvokeFunction
Resource:
- !Sub "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:function:*"
Metadata:
cfn_nag:
rules_to_suppress:
- id: W11
reason: "The * resource is required since the functions need to be created before the state machine"
MediaConvertRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- mediaconvert.amazonaws.com
Action:
- sts:AssumeRole
Policies:
- PolicyName: !Sub "${AWS::StackName}-mediatranscode-policy"
PolicyDocument:
Statement:
- Effect: Allow
Action:
- s3:GetObject
- s3:PutObject
Resource:
- !Sub "${Source.Arn}/*"
- !Sub "${Destination.Arn}/*"
- Effect: Allow
Action:
- execute-api:Invoke
Resource:
- !Sub "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:*"
Metadata:
cfn_nag:
rules_to_suppress:
- id: W11
reason: "/* required to get/put objects to S3"
MediaPackageVodRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- mediapackage.amazonaws.com
Action:
- sts:AssumeRole
Policies:
- PolicyName: !Sub "${AWS::StackName}-mediapackagevod-policy"
PolicyDocument:
Statement:
- Effect: Allow
Action:
- s3:GetObject
- s3:GetBucketLocation
- s3:GetBucketRequestPayment
Resource:
- !Sub "${Destination.Arn}"
- !Sub "${Destination.Arn}/*"
Metadata:
cfn_nag:
rules_to_suppress:
- id: W11
reason: "* is required to get objects from S3"
S3LambdaInvokeVideo:
Type: AWS::Lambda::Permission
Properties:
FunctionName: !GetAtt StepFunctions.Arn
Action: lambda:InvokeFunction
Principal: s3.amazonaws.com
SourceAccount: !Ref AWS::AccountId
CloudWatchLambdaInvokeErrors:
Type: AWS::Lambda::Permission
Properties:
FunctionName: !GetAtt ErrorHandler.Arn
Action: lambda:InvokeFunction
Principal: events.amazonaws.com
SourceArn: !GetAtt EncodeErrorRule.Arn
CloudWatchLambdaInvokeCompletes:
Type: AWS::Lambda::Permission
Properties:
FunctionName: !GetAtt StepFunctions.Arn
Action: lambda:InvokeFunction
Principal: events.amazonaws.com
SourceArn: !GetAtt EncodeCompleteRule.Arn
DestBucketPolicy:
Type: AWS::S3::BucketPolicy
Properties:
Bucket: !Ref Destination
PolicyDocument:
Statement:
- Effect: Allow
Action:
- s3:GetObject
Resource: !Sub "arn:${AWS::Partition}:s3:::${Destination}/*"
Principal:
CanonicalUser: !GetAtt DestinationOriginAccessIdentity.S3CanonicalUserId
EncodeCompleteRule:
Type: AWS::Events::Rule
Properties:
Name: !Sub "${AWS::StackName}-EncodeComplete"
Description: MediaConvert Completed event rule
EventPattern:
source:
- aws.mediaconvert
detail:
status:
- COMPLETE
userMetadata:
workflow:
- !Ref AWS::StackName
Targets:
- Arn: !GetAtt StepFunctions.Arn
Id: !Sub "${AWS::StackName}-StepFunctions"
EncodeErrorRule:
Type: AWS::Events::Rule
Properties:
Name: !Sub "${AWS::StackName}-EncodeError"
Description: MediaConvert Error event rule
EventPattern:
source:
- aws.mediaconvert
detail:
status:
- ERROR
userMetadata:
workflow:
- !Ref AWS::StackName
Targets:
- Arn: !GetAtt ErrorHandler.Arn
Id: !Sub "${AWS::StackName}-EncodeError"
DynamoDBTable:
DeletionPolicy: Retain
UpdateReplacePolicy: Retain
Type: AWS::DynamoDB::Table
Properties:
BillingMode: PAY_PER_REQUEST
PointInTimeRecoverySpecification:
PointInTimeRecoveryEnabled: true
AttributeDefinitions:
- AttributeName: guid
AttributeType: S
- AttributeName: srcBucket
AttributeType: S
- AttributeName: startTime
AttributeType: S
KeySchema:
- AttributeName: guid
KeyType: HASH
GlobalSecondaryIndexes:
- IndexName: srcBucket-startTime-index
KeySchema:
- AttributeName: srcBucket
KeyType: HASH
- AttributeName: startTime
KeyType: RANGE
Projection:
ProjectionType: ALL
TableName: !Ref AWS::StackName
Metadata:
cfn_nag:
rules_to_suppress:
- id: W28
reason: "Table name is set to the stack name"
- id: W74
reason: " The DynamoDB table is configured to use the default encryption"
Source:
DeletionPolicy: Retain
UpdateReplacePolicy: Retain
Type: AWS::S3::Bucket
Properties:
LoggingConfiguration:
DestinationBucketName: !Ref Logs
LogFilePrefix: s3-access/
LifecycleConfiguration:
Rules:
- Id: !Sub "${AWS::StackName}-source-archive"
TagFilters:
- Key: !Ref AWS::StackName
Value: GLACIER
Status: Enabled
Transitions:
- TransitionInDays: 1
StorageClass: GLACIER
- Id: !Sub "${AWS::StackName}-source-deep-archive"
TagFilters:
- Key: !Ref AWS::StackName
Value: DEEP_ARCHIVE
Status: Enabled
Transitions:
- TransitionInDays: 1
StorageClass: DEEP_ARCHIVE
BucketEncryption:
ServerSideEncryptionConfiguration:
- ServerSideEncryptionByDefault:
SSEAlgorithm: AES256
PublicAccessBlockConfiguration:
BlockPublicAcls: true
BlockPublicPolicy: true
IgnorePublicAcls: true
RestrictPublicBuckets: true
Metadata:
cfn_nag:
rules_to_suppress:
- id: W51
reason: "Bucket does not need a bucket policy"
Destination:
DeletionPolicy: Retain
UpdateReplacePolicy: Retain
Type: AWS::S3::Bucket
Properties:
LoggingConfiguration:
DestinationBucketName: !Ref Logs
LogFilePrefix: s3-access/
CorsConfiguration:
CorsRules:
- AllowedMethods: [GET]
AllowedOrigins: ['*']
AllowedHeaders: ['*']
MaxAge: 3000
PublicAccessBlockConfiguration:
BlockPublicAcls: true
BlockPublicPolicy: true
IgnorePublicAcls: true
RestrictPublicBuckets: true
BucketEncryption:
ServerSideEncryptionConfiguration:
- ServerSideEncryptionByDefault:
SSEAlgorithm: AES256
Logs:
DeletionPolicy: Retain
UpdateReplacePolicy: Retain
Type: AWS::S3::Bucket
Properties:
AccessControl: LogDeliveryWrite
BucketEncryption:
ServerSideEncryptionConfiguration:
- ServerSideEncryptionByDefault:
SSEAlgorithm: AES256
PublicAccessBlockConfiguration:
BlockPublicAcls: true
BlockPublicPolicy: true
IgnorePublicAcls: true
RestrictPublicBuckets: true
Metadata:
cfn_nag:
rules_to_suppress:
- id: W35
reason: "Used to store access logs for other buckets"
- id: W51
reason: "Bucket does not need a bucket policy"
SnsTopic:
Type: AWS::SNS::Topic
Properties:
DisplayName: !Sub "${AWS::StackName}-Notifications"
KmsMasterKeyId: alias/aws/sns
Subscription:
- Endpoint: !Ref AdminEmail
Protocol: email
SqsQueue:
Type: AWS::SQS::Queue
Properties:
VisibilityTimeout: 120
QueueName: !Sub ${AWS::StackName}
RedrivePolicy:
deadLetterTargetArn: !Sub ${SqsQueueDlq.Arn}
maxReceiveCount: 1
KmsDataKeyReusePeriodSeconds: 300
KmsMasterKeyId: alias/aws/sqs
SqsQueueDlq:
Type: AWS::SQS::Queue
Properties:
VisibilityTimeout: 120
QueueName: !Sub ${AWS::StackName}-dlq
KmsDataKeyReusePeriodSeconds: 300
KmsMasterKeyId: alias/aws/sqs
DestinationOriginAccessIdentity:
Type: AWS::CloudFront::CloudFrontOriginAccessIdentity
Properties:
CloudFrontOriginAccessIdentityConfig:
Comment: !Sub "access-identity-${Destination}"
CloudFront:
Type: AWS::CloudFront::Distribution
Properties:
DistributionConfig:
Origins:
- DomainName: !Sub "${Destination}.s3.${AWS::Region}.amazonaws.com"
Id: vodS3Origin
S3OriginConfig:
OriginAccessIdentity: !Sub "origin-access-identity/cloudfront/${DestinationOriginAccessIdentity}"
Enabled: true
Logging:
IncludeCookies: false
Bucket: !GetAtt Logs.DomainName
Prefix: cloudfront-logs/
DefaultCacheBehavior:
AllowedMethods:
- GET
- HEAD
Compress: true
MaxTTL: 0
MinTTL: 0
ViewerProtocolPolicy: "redirect-to-https"
DefaultTTL: 0
TargetOriginId: vodS3Origin
ForwardedValues:
QueryString: false
Cookies:
Forward: none
Headers:
- Origin
- Access-Control-Request-Method
- Access-Control-Request-Headers
PriceClass: PriceClass_100
ViewerCertificate:
CloudFrontDefaultCertificate: true
Metadata:
cfn_nag:
rules_to_suppress:
- id: W70
reason: "CloudFront automatically sets the security policy to TLSv1 when the distribution uses the CloudFront domain name (CloudFrontDefaultCertificate=true)"
S3Config:
DependsOn: CloudFront
Type: Custom::S3
Properties:
ServiceToken: !GetAtt CustomResource.Arn
Source: !Ref Source
IngestArn: !GetAtt StepFunctions.Arn
Resource: S3Notification
WorkflowTrigger: !Ref WorkflowTrigger
MediaConvertEndPoint:
Type: Custom::LoadLambda
Properties:
ServiceToken: !GetAtt CustomResource.Arn
Resource: EndPoint
MediaConvertTemplates:
Type: Custom::LoadLambda
Properties:
ServiceToken: !GetAtt CustomResource.Arn
Resource: MediaConvertTemplates
StackName: !Ref AWS::StackName
EndPoint: !GetAtt MediaConvertEndPoint.EndpointUrl
EnableMediaPackage: !Ref EnableMediaPackage
EnableNewTemplates: true
MediaPackageVod:
Type: Custom::LoadLambda
Properties:
ServiceToken: !GetAtt CustomResource.Arn
Resource: MediaPackageVod
StackName: !Ref AWS::StackName
GroupId: !Sub "${AWS::StackName}-packaging-group"
PackagingConfigurations: "HLS,DASH,MSS,CMAF"
DistributionId: !Ref CloudFront
EnableMediaPackage: !Ref EnableMediaPackage
CustomResource:
Type: AWS::Lambda::Function
Properties:
FunctionName: !Sub "${AWS::StackName}-custom-resource"
Description: Used to deploy resources not supported by CloudFormation
Handler: index.handler
Role: !GetAtt CustomResourceRole.Arn
Code:
S3Bucket: !Join ["-", [!FindInMap ["SourceCode", "General", "S3Bucket"], Ref: "AWS::Region"]]
S3Key: !Join ["/", [!FindInMap ["SourceCode", "General", "KeyPrefix"], "custom-resource.zip"]]
Runtime: nodejs12.x
Timeout: 180
Environment:
Variables:
AWS_NODEJS_CONNECTION_REUSE_ENABLED: "1"
StepFunctionsRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- sts:AssumeRole
Policies:
- PolicyName: !Sub "${AWS::StackName}-step-functions-role"
PolicyDocument:
Statement:
- Effect: Allow
Action:
- states:StartExecution
Resource:
- !Sub "arn:${AWS::Partition}:states:${AWS::Region}:${AWS::AccountId}:stateMachine:${AWS::StackName}-ingest"
- !Sub "arn:${AWS::Partition}:states:${AWS::Region}:${AWS::AccountId}:stateMachine:${AWS::StackName}-process"
- !Sub "arn:${AWS::Partition}:states:${AWS::Region}:${AWS::AccountId}:stateMachine:${AWS::StackName}-publish"
- Effect: Allow
Action:
- lambda:InvokeFunction
Resource:
- !Sub "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:function:${AWS::StackName}-error-handler"
- Effect: Allow
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Resource:
- !Sub "arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/*"
Metadata:
cfn_nag:
rules_to_suppress:
- id: W11
reason: "* is used so that the Lambda function can create log groups"
StepFunctions:
Type: AWS::Lambda::Function
Properties:
FunctionName: !Sub "${AWS::StackName}-step-functions"
Description: Creates a unique identifer (GUID) and executes the Ingest StateMachine
Handler: index.handler
Role: !GetAtt StepFunctionsRole.Arn
Code:
S3Bucket: !Join ["-", [!FindInMap ["SourceCode", "General", "S3Bucket"], Ref: "AWS::Region"]]
S3Key: !Join ["/", [!FindInMap ["SourceCode", "General", "KeyPrefix"], "step-functions.zip"]]
Runtime: nodejs12.x
Timeout: 120
Environment:
Variables:
AWS_NODEJS_CONNECTION_REUSE_ENABLED: "1"
IngestWorkflow: !Sub "arn:${AWS::Partition}:states:${AWS::Region}:${AWS::AccountId}:stateMachine:${AWS::StackName}-ingest"
ProcessWorkflow: !Sub "arn:${AWS::Partition}:states:${AWS::Region}:${AWS::AccountId}:stateMachine:${AWS::StackName}-process"
PublishWorkflow: !Sub "arn:${AWS::Partition}:states:${AWS::Region}:${AWS::AccountId}:stateMachine:${AWS::StackName}-publish"
ErrorHandler: !GetAtt ErrorHandler.Arn
InputValidateRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- sts:AssumeRole
Policies:
- PolicyName: !Sub "${AWS::StackName}-input-validate-role"
PolicyDocument:
Statement:
- Effect: Allow
Action:
- s3:GetObject
Resource:
- !Sub "${Source.Arn}/*"
- Effect: Allow
Action:
- lambda:InvokeFunction
Resource:
- !Sub "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:function:${AWS::StackName}-error-handler"
- Effect: Allow
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Resource:
- !Sub "arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/*"
Metadata:
cfn_nag:
rules_to_suppress:
- id: W11
reason: "* is used so that the Lambda function can create log groups; S3 action is limited to one bucket"
InputValidate:
Type: AWS::Lambda::Function
Properties:
FunctionName: !Sub "${AWS::StackName}-input-validate"
Description: Validates the input given to the workflow
Handler: index.handler
Role: !GetAtt InputValidateRole.Arn
Code:
S3Bucket: !Join ["-", [!FindInMap ["SourceCode", "General", "S3Bucket"], Ref: "AWS::Region"]]
S3Key: !Join ["/", [!FindInMap ["SourceCode", "General", "KeyPrefix"], "input-validate.zip"]]
Runtime: nodejs12.x
Timeout: 120
Environment:
Variables:
AWS_NODEJS_CONNECTION_REUSE_ENABLED: "1"
ErrorHandler: !GetAtt ErrorHandler.Arn
WorkflowName: !Ref AWS::StackName
Source: !Ref Source
Destination: !Ref Destination
FrameCapture: !Ref FrameCapture
ArchiveSource: !Ref Glacier
MediaConvert_Template_2160p:
!If
- IsMediaPackageEnabled
- !Sub "${AWS::StackName}_Ott_2160p_Avc_Aac_16x9_mvod_no_preset"
- !Sub "${AWS::StackName}_Ott_2160p_Avc_Aac_16x9_qvbr_no_preset"
MediaConvert_Template_1080p:
!If
- IsMediaPackageEnabled
- !Sub "${AWS::StackName}_Ott_1080p_Avc_Aac_16x9_mvod_no_preset"
- !Sub "${AWS::StackName}_Ott_1080p_Avc_Aac_16x9_qvbr_no_preset"
MediaConvert_Template_720p:
!If
- IsMediaPackageEnabled
- !Sub "${AWS::StackName}_Ott_720p_Avc_Aac_16x9_mvod_no_preset"
- !Sub "${AWS::StackName}_Ott_720p_Avc_Aac_16x9_qvbr_no_preset"
CloudFront: !GetAtt CloudFront.DomainName
EnableMediaPackage: !Ref EnableMediaPackage
InputRotate: DEGREE_0
EnableSns: !Ref EnableSns
EnableSqs: !Ref EnableSqs
AcceleratedTranscoding: !Ref AcceleratedTranscoding
MediainfoRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- sts:AssumeRole
Policies:
- PolicyName: !Sub "${AWS::StackName}-mediainfo-role"
PolicyDocument:
Statement:
- Effect: Allow
Action:
- s3:GetObject
Resource:
- !Sub "${Source.Arn}/*"
- Effect: Allow
Action:
- lambda:InvokeFunction
Resource:
- !Sub "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:function:${AWS::StackName}-error-handler"
- Effect: Allow
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Resource:
- !Sub "arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/*"
Metadata:
cfn_nag:
rules_to_suppress:
- id: W11
reason: "* is limited to one S3 bucket"
Mediainfo:
Type: AWS::Lambda::Function
Properties:
FunctionName: !Sub "${AWS::StackName}-mediainfo"
Description: Runs mediainfo on a pre-signed S3 URL
Handler: lambda_function.lambda_handler
Role: !GetAtt MediainfoRole.Arn
Code:
S3Bucket: !Join ["-", [!FindInMap ["SourceCode", "General", "S3Bucket"], Ref: "AWS::Region"]]
S3Key: !Join ["/", [!FindInMap ["SourceCode", "General", "KeyPrefix"], "mediainfo.zip"]]
Runtime: python3.7
Timeout: 120
Environment:
Variables:
ErrorHandler: !GetAtt ErrorHandler.Arn
DynamoUpdateRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- sts:AssumeRole
Policies:
- PolicyName: !Sub "${AWS::StackName}-dynamo-role"
PolicyDocument:
Statement:
- Effect: Allow
Action:
- lambda:InvokeFunction
Resource:
- !Sub "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:function:${AWS::StackName}-error-handler"
- Effect: Allow
Action:
- dynamodb:UpdateItem
Resource:
- !Sub "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${DynamoDBTable}"
- Effect: Allow
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Resource:
- !Sub "arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/*"
Metadata:
cfn_nag:
rules_to_suppress:
- id: W11
reason: "* is used so that the Lambda function can create log groups"
DynamodbUpdate:
Type: AWS::Lambda::Function
Properties:
FunctionName: !Sub "${AWS::StackName}-dynamo"
Description: Updates DynamoDB with event data
Handler: index.handler
Role: !GetAtt DynamoUpdateRole.Arn
Code:
S3Bucket: !Join ["-", [!FindInMap ["SourceCode", "General", "S3Bucket"], Ref: "AWS::Region"]]
S3Key: !Join ["/", [!FindInMap ["SourceCode", "General", "KeyPrefix"], "dynamo.zip"]]
Runtime: nodejs12.x
Timeout: 120
Environment:
Variables:
AWS_NODEJS_CONNECTION_REUSE_ENABLED: "1"
DynamoDBTable: !Ref DynamoDBTable
ErrorHandler: !GetAtt ErrorHandler.Arn
ProfilerRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- sts:AssumeRole
Policies:
- PolicyName: !Sub "${AWS::StackName}-profiler-role"
PolicyDocument:
Statement:
- Effect: Allow
Action:
- lambda:InvokeFunction
Resource:
- !Sub "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:function:${AWS::StackName}-error-handler"
- Effect: Allow
Action:
- dynamodb:GetItem
Resource:
- !Sub "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${DynamoDBTable}"
- Effect: Allow
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Resource:
- !Sub "arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/*"
Metadata:
cfn_nag:
rules_to_suppress:
- id: W11
reason: "* is used so that the Lambda function can create log groups"
Profiler:
Type: AWS::Lambda::Function
Properties:
FunctionName: !Sub "${AWS::StackName}-profiler"
Description: Sets an EncodeProfile based on mediainfo output
Handler: index.handler
Role: !GetAtt ProfilerRole.Arn
Code:
S3Bucket: !Join ["-", [!FindInMap ["SourceCode", "General", "S3Bucket"], Ref: "AWS::Region"]]
S3Key: !Join ["/", [!FindInMap ["SourceCode", "General", "KeyPrefix"], "profiler.zip"]]
Runtime: nodejs12.x
Timeout: 120
Environment:
Variables:
AWS_NODEJS_CONNECTION_REUSE_ENABLED: "1"
DynamoDBTable: !Ref DynamoDBTable
ErrorHandler: !GetAtt ErrorHandler.Arn
EncodeRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- sts:AssumeRole
Policies:
- PolicyName: !Sub "${AWS::StackName}-encode-role"
PolicyDocument:
Statement:
- Effect: Allow
Action:
- lambda:InvokeFunction
Resource:
- !Sub "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:function:${AWS::StackName}-error-handler"
- Effect: Allow
Action:
- mediaconvert:CreateJob
- mediaconvert:GetJobTemplate
Resource:
- !Sub "arn:${AWS::Partition}:mediaconvert:${AWS::Region}:${AWS::AccountId}:*"
- Effect: Allow
Action:
- iam:PassRole
Resource:
- !GetAtt MediaConvertRole.Arn
- Effect: Allow
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Resource:
- !Sub "arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/*"
Metadata:
cfn_nag:
rules_to_suppress:
- id: W11
reason: "* is used so that the Lambda function can create log groups; MediaConvert job ids are randomly generated"
Encode:
Type: AWS::Lambda::Function
Properties:
FunctionName: !Sub "${AWS::StackName}-encode"
Description: Creates a MediaConvert encode job
Handler: index.handler
Role: !GetAtt EncodeRole.Arn
Code:
S3Bucket: !Join ["-", [!FindInMap ["SourceCode", "General", "S3Bucket"], Ref: "AWS::Region"]]
S3Key: !Join ["/", [!FindInMap ["SourceCode", "General", "KeyPrefix"], "encode.zip"]]
Runtime: nodejs12.x
Timeout: 120
Environment:
Variables:
AWS_NODEJS_CONNECTION_REUSE_ENABLED: "1"
ErrorHandler: !GetAtt ErrorHandler.Arn
MediaConvertRole: !GetAtt MediaConvertRole.Arn
EndPoint: !GetAtt MediaConvertEndPoint.EndpointUrl
OutputValidateRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service: