-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathstate-machine.asl.yml
More file actions
1226 lines (1110 loc) · 48.5 KB
/
Copy pathstate-machine.asl.yml
File metadata and controls
1226 lines (1110 loc) · 48.5 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
QueryLanguage: JSONPath
StartAt: Normalize Input
States:
# Start of pre-processing
Normalize Input:
# Sample input:
# { Job: { Id: "123", Source: {…}, Tasks: […], Callbacks: […] } }
# Sample output:
# {
# Job: { Id: "123", Source: {…}, Tasks: […], Callbacks: […], SerializedJobs: […], ExecutionTrace: […] },
# State: "DONE"
# }
Type: Task
QueryLanguage: JSONPath
Comment: Normalizes execution input
Retry:
- { ErrorEquals: [MissingTaskTypeError], MaxAttempts: 0 } # Don't retry
- { ErrorEquals: [States.ALL], IntervalSeconds: 1, MaxAttempts: 2, BackoffRate: 1 }
Catch:
# Add the error object to the state input before passing to the catcher
- { ErrorEquals: [States.ALL], ResultPath: "$.Error", Next: Normalize Input Catcher }
Resource: "${NormalizeInputLambdaFunctionArn}"
Parameters: # Payload provided to the Lambda function
Input.$: "$"
# Proceed down the happy path
Next: JobReceived Callbacks Map
Normalize Input Catcher:
# Sample input
# {
# Job: { Id: "123", Source: {…}, Tasks: […], Callbacks: […] },
# Error: {…}
# }
# Sample output:
# {
# Job: { Id: "123", Source: {…}, Tasks: […], Callbacks: […] },
# Error: {…},
# State: NORMALIZE_INPUT_ERROR
# }
Type: Pass
QueryLanguage: JSONPath
Comment: Add a field to the state so normalize errors can be identified
# Set the output State to a static string value
Result: NORMALIZE_INPUT_ERROR
ResultPath: "$.State"
# Skip to post-processing
Next: Add Empty TasksMapResults
JobReceived Callbacks Map:
# Sample input:
# {
# Job: { Id: "123", Source: {…}, Tasks: […], Callbacks: […], SerializedJobs: […], ExecutionTrace: […] },
# State: "DONE"
# }
# Sample output:
# {
# Job: { Id: "123", Source: {…}, Tasks: […], Callbacks: […], SerializedJobs: […], ExecutionTrace: […] },
# State: "DONE",
# JobReceivedMapResultNulls: [null, null]
# }
Type: Map
QueryLanguage: JSONPath
Comment: Iterates over all callback endpoints to indicate the job was received
# Retries are handled directly on the callback state in the iterator
# If callbacks fail, there's no point in having a fallback catcher, since we would only use that to send callbacks
# Add the result of the Map (an array containing the results of each iteration) to the default output
# (This field will not be shown in future sample state data)
ResultPath: "$.JobReceivedMapResultNulls"
# Proceed down the happy path
Next: Ingest Source File
MaxConcurrency: 0
ItemsPath: "$.Job.Callbacks" # This references post-InputPath input
ItemSelector: # Initial state for each ItemProcessor iteration
Callback.$: "$$.Map.Item.Value" # Reference the current item being processed from the array indicated by ItemsPath
StateMachine:
Id.$: "$$.StateMachine.Id"
Execution:
Id.$: "$$.Execution.Id"
Message: # The callbacks Lambda function uses the JSON of this value as the message sent to each callback
JobReceived: # The `JobReceived` field MUST be included in these callback messages per our published API
Job:
Id.$: "$.Job.Id"
Execution:
Id.$: "$$.Execution.Id"
State: RECEIVED
ItemProcessor:
ProcessorConfig: { Mode: INLINE }
StartAt: Send JobReceived Callback
States:
Send JobReceived Callback:
# Sample input:
# {
# Callback: {…},
# StateMachine: { Id: "wxyz" },
# Execution: { Id: "a1b2c3" },
# Message: {…}
# }
# Sample output: (will become an element in JobReceivedMapResultNulls)
# null
Type: Task
QueryLanguage: JSONPath
Comment: >-
Sends a job received message for a single callback endpoint in
the iterator
Resource: "${CallbackLambdaFunctionArn}"
Retry:
- { ErrorEquals: [States.ALL], IntervalSeconds: 5, MaxAttempts: 3, BackoffRate: 2 }
End: true
Ingest Source File:
# Sample input:
# {
# Job: { Id: "123", Source: {…}, Tasks: […], Callbacks: […], SerializedJobs: […], ExecutionTrace: […] },
# State: "DONE"
# }
# Sample output:
# {
# Job: { Id: "123", Source: {…}, Tasks: […], Callbacks: […], SerializedJobs: […], ExecutionTrace: […] },
# State: "DONE",
# Artifact: {…}
# }
Type: Task
QueryLanguage: JSONPath
Comment: Creates an artifact in S3 of the source file
Retry:
- { ErrorEquals: [UnknownSourceModeError], MaxAttempts: 0 } # Don't retry
- { ErrorEquals: [States.ALL], IntervalSeconds: 5, MaxAttempts: 3, BackoffRate: 2 }
Catch:
# Add the error object to the state input before passing to the catcher
- { ErrorEquals: [States.ALL], ResultPath: "$.Error", Next: Ingest Source File Catcher }
Resource: "${IngestLambdaFunctionArn}"
Parameters: # Payload provided to the Lambda function
Job:
Source.$: "$.Job.Source"
Execution:
Id.$: "$$.Execution.Id"
# Add the return value of the Lambda function to the default state output
ResultPath: "$.Artifact"
# Proceed down the happy path
Next: Detect Source File Type
Ingest Source File Catcher:
# Sample input:
# {
# Job: { Id: "123", Source: {…}, Tasks: […], Callbacks: […], SerializedJobs: […], ExecutionTrace: […] },
# State: "DONE",
# Error: {}
# }
# Sample output:
# {
# Job: { Id: "123", Source: {…}, Tasks: […], Callbacks: […], SerializedJobs: […], ExecutionTrace: […] },
# State: SOURCE_FILE_INGEST_ERROR,
# Error: {}
# }
Type: Pass
QueryLanguage: JSONPath
Comment: Add a field to the state so ingest errors can be identified
# Set the output State to a static string value
Result: SOURCE_FILE_INGEST_ERROR
ResultPath: "$.State"
# Skip to post-processing
Next: Add Empty TasksMapResults
Detect Source File Type:
# Sample input:
# {
# Job: { Id: "123", Source: {…}, Tasks: […], Callbacks: […], SerializedJobs: […], ExecutionTrace: […] },
# State: "DONE",
# Artifact: {…}
# }
# Sample output:
# {
# Job: { Id: "123", Source: {…}, Tasks: […], Callbacks: […], SerializedJobs: […], ExecutionTrace: […] },
# State: "DONE",
# Artifact: { …, Descriptor: {…} }
# }
Comment: Detects the file type of the source file artifact
Type: Task
QueryLanguage: JSONPath
Retry:
- { ErrorEquals: [States.ALL], IntervalSeconds: 5, MaxAttempts: 3, BackoffRate: 2 }
Catch:
# Add the error object to the state input before passing to the catcher
- { ErrorEquals: [States.ALL], ResultPath: "$.Error", Next: Detect Source File Type Catcher }
Resource: "${SourceTypeLambdaFunctionArn}"
Parameters: # Payload provided to the Lambda function
Artifact.$: "$.Artifact"
# Add the return value of the Lambda function to the default state output
ResultPath: "$.Artifact.Descriptor"
# Proceed down the happy path
Next: Tasks Map
Detect Source File Type Catcher:
# Sample input:
# {
# Job: { Id: "123", Source: {…}, Tasks: […], Callbacks: […], SerializedJobs: […], ExecutionTrace: […] },
# State: "DONE",
# Artifact: {…},
# Error: {…}
# }
# Sample output:
# {
# Job: { Id: "123", Source: {…}, Tasks: […], Callbacks: […], SerializedJobs: […], ExecutionTrace: […] },
# State: "SOURCE_FILE_TYPE_DETECTION_ERROR",
# Artifact: {…},
# Error: {…}
# }
Type: Pass
QueryLanguage: JSONPath
Comment: Add a field to the state so type detection errors can be identified
# Set the output State to a static string value
Result: SOURCE_FILE_TYPE_DETECTION_ERROR
ResultPath: "$.State"
# Skip to post-processing
Next: Add Empty TasksMapResults
# End of pre-processing
# Start of task execution
Tasks Map:
# The `TasksMapResults` field in the output will be an array, where each element is the final output of an iteration of
# the map. For example, if a job has three tasks, `TasksMapResults` will be an array with three elements, regardless of
# whether those tasks succeeded or failed.
#
# For successful tasks (those that aren't caught for any reason), the element in the array will be an object with
# the task's results, like { Task: "___SOME_TASK__TYPE___", …other task-specifc fields }.
#
# For unsuccessful tasks (those caught for any reason), the element will be the original task definition from the
# job, such as { Type: "___SOME_TASK__TYPE___" }.
#
# Note the distinction between the `Task` and `Type` fields in the two different cases.
#
# Sample input:
# {
# Job: { Id: "123", Source: {…}, Tasks: […], Callbacks: […], SerializedJobs: […], ExecutionTrace: […] },
# State: "DONE",
# Artifact: { Descriptor: {…} }
# }
# Sample output:
# {
# Job: { Id: "123", Source: {…}, Tasks: […], Callbacks: […], SerializedJobs: […], ExecutionTrace: […] },
# State: "DONE",
# Artifact: { Descriptor: {…} },
# TasksMapResults: […]
# }
Type: Map
QueryLanguage: JSONPath
Comment: Iterates over all tasks included in the job
Catch:
# Add the error object to the state input before passing to the catcher
- { ErrorEquals: [States.ALL], ResultPath: "$.Error", Next: Tasks Map Catcher }
# Add the result of the Map (an array containing the results of each iteration) to the default output
ResultPath: "$.TasksMapResults"
# Proceed down the happy path
Next: JobResult Callback Map
MaxConcurrency: 0
ItemsPath: "$.Job.Tasks" # This references post-InputPath input
ItemSelector: # Initial state for each ItemProcessor iteration
Job:
Id.$: "$.Job.Id"
Execution:
Id.$: "$$.Execution.Id"
Artifact.$: "$.Artifact"
TaskIndex.$: "$$.Map.Item.Index"
Task.$: "$$.Map.Item.Value" # This is the current iteration's element from Job.Tasks, e.g., { "Type": "Copy" }
Callbacks.$: "$.Job.Callbacks"
ItemProcessor:
ProcessorConfig: { Mode: INLINE }
StartAt: Route Task By Type
States:
# The general shape of a task map iteration is:
# 1. Route the task, based on Task.Type
# 2. One or more task-specific states that do the work
# 3. Send callbacks with the task results
# One of two callback states will send callbacks, depending on if the
# task was successful. Because these callback states are the final
# states of the iteration, their output is important: it will be what
# ends up in the map's ResultPath ($.TasksMapResults).
#
# All task-specific states, not just the final state, should catch
# to the TaskResult Error Callback Map.
#
# The ResultPath for states that are returning the final output of a
# task's operation (i.e., states immediately prior to the callbacks
# map) must be $.TaskResult, and their return value must be the
# expected standard task output (e.g., { Task: 'Copy' })
Route Task By Type:
# Sample input/output: See map's ItemSelector
Type: Choice
QueryLanguage: JSONPath
Comment: >-
For the current task being iterated, routes to the appropriate
state
Default: Unknown Task Type
Choices:
- Variable: "$.Task.Type"
StringEquals: Inspect
Next: Inspect Task Handler
- And:
- Variable: "$.Task.Type"
StringEquals: Copy
- Variable: "$.Task.Mode"
StringEquals: AWS/S3
Next: Copy Task Handler
- And:
- Variable: "$.Task.Type"
StringEquals: Copy
- Variable: "$.Task.Mode"
StringEquals: FTP/Passive
Next: FTP Copy Task Fargate Execution
- And:
- Variable: "$.Task.Type"
StringEquals: Copy
- Variable: "$.Task.Mode"
StringEquals: FTP/Active
Next: FTP Copy Task Fargate Execution
- And:
- Variable: "$.Task.Type"
StringEquals: Copy
- Variable: "$.Task.Mode"
StringEquals: FTP/Auto
Next: FTP Copy Task Fargate Execution
- Variable: "$.Task.Type"
StringEquals: Transcode
Next: Transcode Task Fargate Execution
- Variable: "$.Task.Type"
StringEquals: HLS
Next: HLS Task Fargate Execution
- Variable: "$.Task.Type"
StringEquals: Image
Next: Image Task Handler
- Variable: "$.Task.Type"
StringEquals: Transcribe
Next: Transcribe Task Job Start
- Variable: "$.Task.Type"
StringEquals: WavWrap
Next: WAV Wrap Task Handler
- Variable: "$.Task.Type"
StringEquals: DetectSilence
Next: Detect Silence Task Handler
- Variable: "$.Task.Type"
StringEquals: DetectTone
Next: Detect Tone Task Handler
- Variable: "$.Task.Type"
StringEquals: DetectEas
Next: Detect EAS Task Handler
- Variable: "$.Task.Type"
StringEquals: Waveform
Next: Waveform Task Handler
# This is a no-op. No callbacks are sent, and any record of this task
# will be filtered out of the job result callbacks
Unknown Task Type:
# Sample output:
# { Task: "UnknownTaskType" }
Type: Pass
QueryLanguage: JSONPath
Comment: Handles and blackholes tasks with an unknown type
# Even though we do no work for this task, we still return a
# reasonably-well-formed result from the ItemProcessor, which will
# appear in the Map state's results array.
Result:
Task: "UnknownTaskType"
End: true
Inspect Task Handler:
# Sample input: See map's ItemSelector
# Sample output: ItemSelector with TaskResult
Type: Task
QueryLanguage: JSONPath
Comment: Inspects the artifact file
Retry:
- { ErrorEquals: [States.ALL], IntervalSeconds: 5, MaxAttempts: 3, BackoffRate: 2 }
Catch:
- { ErrorEquals: [States.ALL], ResultPath: "$.Error", Next: TaskResult Error Callback Map }
Resource: "${InspectMediaLambdaFunctionArn}"
Parameters: # Payload provided to the Lambda function
Job:
Id.$: "$.Job.Id"
Artifact.$: "$.Artifact"
Task.$: "$.Task"
# Add the return value of the Lambda function to the default state output
ResultPath: "$.TaskResult"
Next: TaskResult Callbacks Map
Copy Task Handler:
# Sample input: See map's ItemSelector
# Sample output: ItemSelector with TaskResult
Type: Task
QueryLanguage: JSONPath
Comment: Copies the artifact
Retry:
- { ErrorEquals: [UnknownCopyTaskModeError], MaxAttempts: 0 }
- { ErrorEquals: [States.ALL], IntervalSeconds: 5, MaxAttempts: 3, BackoffRate: 2 }
Catch:
- { ErrorEquals: [States.ALL], ResultPath: "$.Error", Next: TaskResult Error Callback Map }
Resource: "${CopyLambdaFunctionArn}"
Parameters: # Payload provided to the Lambda function
Job:
Id.$: "$.Job.Id"
Artifact.$: "$.Artifact"
Task.$: "$.Task"
# Add the return value of the Lambda function to the default state output
ResultPath: "$.TaskResult"
Next: TaskResult Callbacks Map
FTP Copy Task Fargate Execution:
# Sample input: See map's ItemSelector
# Sample output: ItemSelector with TaskResult
Type: Task
QueryLanguage: JSONPath
Comment: Sends artifact to an FTP destination
Retry:
- { ErrorEquals: [States.ALL], IntervalSeconds: 10, MaxAttempts: 3, BackoffRate: 2 }
Catch:
- { ErrorEquals: [States.ALL], ResultPath: "$.Error", Next: TaskResult Error Callback Map }
# Add the return value of the Fargate task to the default state output
ResultPath: "$.TaskResult"
Next: TaskResult Callbacks Map
Resource: arn:aws:states:::ecs:runTask.waitForTaskToken
Parameters: # Fargate RunTask request parameters
Cluster: "${EcsClusterArn}"
LaunchType: FARGATE
Overrides:
ContainerOverrides:
- Environment:
- Name: STATE_MACHINE_ARN
Value.$: "$$.StateMachine.Id"
- Name: STATE_MACHINE_NAME
Value.$: "$$.StateMachine.Name"
- Name: STATE_MACHINE_EXECUTION_ID
Value.$: "$$.Execution.Id"
- Name: STATE_MACHINE_JOB_ID
Value.$: "$.Job.Id"
- Name: STATE_MACHINE_TASK_INDEX
Value.$: States.Format('{}', $.TaskIndex)
- Name: STATE_MACHINE_AWS_REGION
Value: "${AwsRegion}"
- Name: STATE_MACHINE_ARTIFACT_BUCKET_NAME
Value.$: "$.Artifact.BucketName"
- Name: STATE_MACHINE_ARTIFACT_OBJECT_KEY
Value.$: "$.Artifact.ObjectKey"
- Name: STATE_MACHINE_TASK_JSON
Value.$: States.JsonToString($.Task)
- Name: STATE_MACHINE_TASK_TOKEN
Value.$: "$$.Task.Token"
- Name: STATE_MACHINE_TASK_TYPE
Value.$: "$.Task.Type"
Name: "${FtpCopyContainerName}"
NetworkConfiguration:
AwsvpcConfiguration:
AssignPublicIp: ENABLED
SecurityGroups:
- "${FtpCopyEcsTaskSecurityGroupId}"
Subnets:
- "${VpcPublicSubnet1}"
- "${VpcPublicSubnet2}"
PropagateTags: TASK_DEFINITION
TaskDefinition: "${FtpCopyEcsTaskDefinitionArn}"
Transcode Task Fargate Execution:
# Sample input: See map's ItemSelector
# Sample output: ItemSelector with TaskResult
Type: Task
QueryLanguage: JSONPath
Comment: Transcodes multimedia artifact
Retry:
- { ErrorEquals: [States.ALL], IntervalSeconds: 15, MaxAttempts: 5, BackoffRate: 2 }
Catch:
- { ErrorEquals: [States.ALL], ResultPath: "$.Error", Next: TaskResult Error Callback Map }
# Add the return value of the Fargate task to the default state output
ResultPath: "$.TaskResult"
Next: TaskResult Callbacks Map
Resource: arn:aws:states:::ecs:runTask.waitForTaskToken
Parameters: # Fargate RunTask request parameters
Cluster: "${EcsClusterArn}"
LaunchType: FARGATE
Overrides:
ContainerOverrides:
- Environment:
- Name: STATE_MACHINE_ARN
Value.$: "$$.StateMachine.Id"
- Name: STATE_MACHINE_NAME
Value.$: "$$.StateMachine.Name"
- Name: STATE_MACHINE_EXECUTION_ID
Value.$: "$$.Execution.Id"
- Name: STATE_MACHINE_JOB_ID
Value.$: "$.Job.Id"
- Name: STATE_MACHINE_TASK_INDEX
Value.$: States.Format('{}', $.TaskIndex)
- Name: STATE_MACHINE_S3_DESTINATION_WRITER_ROLE
Value: "${S3DestinationWriterRoleArn}"
- Name: STATE_MACHINE_AWS_REGION
Value: "${AwsRegion}"
- Name: STATE_MACHINE_ARTIFACT_BUCKET_NAME
Value.$: "$.Artifact.BucketName"
- Name: STATE_MACHINE_ARTIFACT_OBJECT_KEY
Value.$: "$.Artifact.ObjectKey"
- Name: STATE_MACHINE_DESTINATION_JSON
Value.$: States.JsonToString($.Task.Destination)
- Name: STATE_MACHINE_DESTINATION_MODE
Value.$: "$.Task.Destination.Mode"
- Name: STATE_MACHINE_DESTINATION_BUCKET_NAME
Value.$: "$.Task.Destination.BucketName"
- Name: STATE_MACHINE_DESTINATION_OBJECT_KEY
Value.$: "$.Task.Destination.ObjectKey"
- Name: STATE_MACHINE_DESTINATION_FORMAT
Value.$: "$.Task.Format"
- Name: STATE_MACHINE_FFMPEG_GLOBAL_OPTIONS
Value.$: "$.Task.FFmpeg.GlobalOptions"
- Name: STATE_MACHINE_FFMPEG_INPUT_FILE_OPTIONS
Value.$: "$.Task.FFmpeg.InputFileOptions"
- Name: STATE_MACHINE_FFMPEG_OUTPUT_FILE_OPTIONS
Value.$: "$.Task.FFmpeg.OutputFileOptions"
# Guaranteed and required values should be listed and
# accessed directly. Optional or conditional values can be
# pulled from the JSON, to avoid state machine runtime
# errors
- Name: STATE_MACHINE_TASK_JSON
Value.$: States.JsonToString($.Task)
- Name: STATE_MACHINE_ARTIFACT_JSON
Value.$: States.JsonToString($.Artifact)
- Name: STATE_MACHINE_TASK_TOKEN
Value.$: "$$.Task.Token"
- Name: STATE_MACHINE_TASK_TYPE
Value.$: "$.Task.Type"
Name: "${TranscodeContainerName}"
NetworkConfiguration:
AwsvpcConfiguration:
AssignPublicIp: ENABLED
Subnets:
- "${VpcPublicSubnet1}"
- "${VpcPublicSubnet2}"
PropagateTags: TASK_DEFINITION
TaskDefinition: "${TranscodeEcsTaskDefinitionArn}"
Image Task Handler:
# Sample input: See map's ItemSelector
# Sample output: ItemSelector with TaskResult
Type: Task
QueryLanguage: JSONPath
Comment: Manipulates and converts image artifacts
Retry:
- { ErrorEquals: [States.ALL], IntervalSeconds: 5, MaxAttempts: 3, BackoffRate: 2 }
Catch:
- { ErrorEquals: [States.ALL], ResultPath: "$.Error", Next: TaskResult Error Callback Map }
Resource: "${ImageTransformLambdaFunctionArn}"
Parameters: # Payload provided to the Lambda function
Job:
Id.$: "$.Job.Id"
Artifact.$: "$.Artifact"
Task.$: "$.Task"
# Add the return value of the Lambda function to the default state output
ResultPath: "$.TaskResult"
Next: TaskResult Callbacks Map
WAV Wrap Task Handler:
# Sample input: See map's ItemSelector
# Sample output: ItemSelector with TaskResult
Type: Task
QueryLanguage: JSONPath
Comment: WAV wraps audio artifacts
Retry:
- { ErrorEquals: [States.ALL], IntervalSeconds: 5, MaxAttempts: 3, BackoffRate: 2 }
Catch:
- { ErrorEquals: [States.ALL], ResultPath: "$.Error", Next: TaskResult Error Callback Map }
Resource: "${WavWrapLambdaFunctionArn}"
Parameters: # Payload provided to the Lambda function
Job:
Id.$: "$.Job.Id"
Artifact.$: "$.Artifact"
Task.$: "$.Task"
# Add the return value of the Lambda function to the default state output
ResultPath: "$.TaskResult"
Next: TaskResult Callbacks Map
Detect Silence Task Handler:
# Sample input: See map's ItemSelector
# Sample output: ItemSelector with TaskResult
Type: Task
QueryLanguage: JSONPath
Comment: Detects silence in audio files
Retry:
- { ErrorEquals: [States.ALL], IntervalSeconds: 5, MaxAttempts: 3, BackoffRate: 2 }
Catch:
- { ErrorEquals: [States.ALL], ResultPath: "$.Error", Next: TaskResult Error Callback Map }
Resource: "${SilenceDetectionLambdaFunctionArn}"
Parameters: # Payload provided to the Lambda function
Job:
Id.$: "$.Job.Id"
Artifact.$: "$.Artifact"
Task.$: "$.Task"
# Add the return value of the Lambda function to the default state output
ResultPath: "$.TaskResult"
Next: TaskResult Callbacks Map
Detect Tone Task Handler:
# Sample input: See map's ItemSelector
# Sample output: ItemSelector with TaskResult
Type: Task
QueryLanguage: JSONPath
Comment: Detects tones in audio files
Retry:
- { ErrorEquals: [States.ALL], IntervalSeconds: 5, MaxAttempts: 3, BackoffRate: 2 }
Catch:
- { ErrorEquals: [States.ALL], ResultPath: "$.Error", Next: TaskResult Error Callback Map }
Resource: "${ToneDetectionLambdaFunctionArn}"
Parameters: # Payload provided to the Lambda function
Job:
Id.$: "$.Job.Id"
Artifact.$: "$.Artifact"
Task.$: "$.Task"
# Add the return value of the Lambda function to the default state output
ResultPath: "$.TaskResult"
Next: TaskResult Callbacks Map
Detect EAS Task Handler:
# Sample input: See map's ItemSelector
# Sample output: ItemSelector with TaskResult
Type: Task
QueryLanguage: JSONPath
Comment: Detects alert tones in audio files
Retry:
- { ErrorEquals: [States.ALL], IntervalSeconds: 5, MaxAttempts: 3, BackoffRate: 2 }
Catch:
- { ErrorEquals: [States.ALL], ResultPath: "$.Error", Next: TaskResult Error Callback Map }
Resource: "${EasDetectionLambdaFunctionArn}"
Parameters: # Payload provided to the Lambda function
Job:
Id.$: "$.Job.Id"
Artifact.$: "$.Artifact"
Task.$: "$.Task"
# Add the return value of the Lambda function to the default state output
ResultPath: "$.TaskResult"
Next: TaskResult Callbacks Map
Waveform Task Handler:
# Sample input: See map's ItemSelector
# Sample output: ItemSelector with TaskResult
Type: Task
QueryLanguage: JSONPath
Comment: Generates waveform data from audio files
Retry:
- { ErrorEquals: [States.ALL], IntervalSeconds: 5, MaxAttempts: 3, BackoffRate: 2 }
Catch:
- { ErrorEquals: [States.ALL], ResultPath: "$.Error", Next: TaskResult Error Callback Map }
Resource: "${WaveformLambdaFunctionArn}"
Parameters: # Payload provided to the Lambda function
Job:
Id.$: "$.Job.Id"
Artifact.$: "$.Artifact"
Task.$: "$.Task"
# Add the return value of the Lambda function to the default state output
ResultPath: "$.TaskResult"
Next: TaskResult Callbacks Map
Transcribe Task Job Start:
# Sample input: See map's ItemSelector
# Sample output: ItemSelector with TranscriptionJob
Type: Task
QueryLanguage: JSONPath
Comment: Transcribes audio from artifacts
Retry:
- { ErrorEquals: [InvalidTranscribeTaskInputError, UnknownDestinationModeError], MaxAttempts: 0 }
- { ErrorEquals: [States.ALL], IntervalSeconds: 5, MaxAttempts: 3, BackoffRate: 2 }
Catch:
- { ErrorEquals: [States.ALL], ResultPath: "$.Error", Next: TaskResult Error Callback Map }
Resource: arn:${AwsPartition}:states:::lambda:invoke.waitForTaskToken
Parameters:
FunctionName: "${TranscriptionJobStartLambdaFunctionArn}"
Payload: # Payload provided to the Lambda function
Job:
Id.$: "$.Job.Id"
Execution:
Id.$: "$$.Execution.Id"
Artifact.$: "$.Artifact"
Task.$: "$.Task"
TaskIteratorIndex.$: "$.TaskIndex"
TaskToken.$: "$$.Task.Token"
# Add the return value of the Lambda function to the default state output
ResultPath: "$.TranscriptionJob"
Next: Transcribe Task Job Success Handler
Transcribe Task Job Success Handler:
# Sample input: ItemSelector with TranscriptionJob
# Sample output: Input with TaskResult
Type: Task
QueryLanguage: JSONPath
Comment: Formats the output of a transcribe task
Retry:
- { ErrorEquals: [States.ALL], IntervalSeconds: 5, MaxAttempts: 3, BackoffRate: 2 }
Catch:
- { ErrorEquals: [States.ALL], ResultPath: "$.Error", Next: TaskResult Error Callback Map }
Resource: "${TranscriptionJobResultsLambdaFunctionArn}"
Parameters: # Payload provided to the Lambda function
Task.$: "$.Task"
TranscriptionJob.$: "$.TranscriptionJob"
# Add the return value of the Lambda function to the default state output
ResultPath: "$.TaskResult"
Next: TaskResult Callbacks Map
HLS Task Fargate Execution:
# Sample input: See map's ItemSelector
# Sample output: ItemSelector with TaskResult
Type: Task
QueryLanguage: JSONPath
Comment: Prepares an artifact for HLS delivery
Retry:
- { ErrorEquals: [States.ALL], IntervalSeconds: 15, MaxAttempts: 5, BackoffRate: 2 }
Catch:
- { ErrorEquals: [States.ALL], ResultPath: "$.Error", Next: TaskResult Error Callback Map }
# Add the return value of the Fargate task to the default state output
ResultPath: "$.TaskResult"
Next: TaskResult Callbacks Map
Resource: arn:aws:states:::ecs:runTask.waitForTaskToken
# Parameters: # ECS RunTask request parameters
# CapacityProviderStrategy:
# - CapacityProvider: "${BasicCapacityProviderName}"
# Base: 0
# Weight: 1
# Cluster: "${EcsClusterArn}"
Parameters: # ECS RunTask request parameters
Cluster: "${EcsClusterArn}"
LaunchType: FARGATE
Overrides:
ContainerOverrides:
- Environment:
- Name: STATE_MACHINE_ARN
Value.$: "$$.StateMachine.Id"
- Name: STATE_MACHINE_NAME
Value.$: "$$.StateMachine.Name"
- Name: STATE_MACHINE_EXECUTION_ID
Value.$: "$$.Execution.Id"
- Name: STATE_MACHINE_JOB_ID
Value.$: "$.Job.Id"
- Name: STATE_MACHINE_TASK_INDEX
Value.$: States.Format('{}', $.TaskIndex)
- Name: STATE_MACHINE_S3_DESTINATION_WRITER_ROLE
Value: "${S3DestinationWriterRoleArn}"
- Name: STATE_MACHINE_AWS_REGION
Value: "${AwsRegion}"
- Name: STATE_MACHINE_ARTIFACT_BUCKET_NAME
Value.$: "$.Artifact.BucketName"
- Name: STATE_MACHINE_ARTIFACT_OBJECT_KEY
Value.$: "$.Artifact.ObjectKey"
- Name: STATE_MACHINE_DESTINATION_JSON
Value.$: States.JsonToString($.Task.Destination)
- Name: STATE_MACHINE_DESTINATION_MODE
Value.$: "$.Task.Destination.Mode"
- Name: STATE_MACHINE_DESTINATION_BUCKET_NAME
Value.$: "$.Task.Destination.BucketName"
- Name: STATE_MACHINE_DESTINATION_OBJECT_KEY_PREFIX
Value.$: "$.Task.Destination.ObjectKeyPrefix"
# Guaranteed and required values should be listed and
# accessed directly. Optional or conditional values can be
# pulled from the JSON, to avoid state machine runtime
# errors
- Name: STATE_MACHINE_TASK_JSON
Value.$: States.JsonToString($.Task)
- Name: STATE_MACHINE_ARTIFACT_JSON
Value.$: States.JsonToString($.Artifact)
- Name: STATE_MACHINE_TASK_TOKEN
Value.$: "$$.Task.Token"
- Name: STATE_MACHINE_TASK_TYPE
Value.$: "$.Task.Type"
Name: "${HlsContainerName}"
NetworkConfiguration:
AwsvpcConfiguration:
AssignPublicIp: ENABLED
Subnets:
- "${VpcPublicSubnet1}"
- "${VpcPublicSubnet2}"
- "${VpcPublicSubnet3}"
PropagateTags: TASK_DEFINITION
TaskDefinition: "${HlsEcsTaskDefinitionArn}"
# Task callbacks
# All valid tasks operations end up at one of these callback states,
# depending on whether the task was successful or not. The value for
# a given task in the TasksMapResults array coming out of the Tasks Map
# will be the output whichever of these callback states is used.
#
# For failed tasks, the task callback will include information about
# the error. This information is not included in the job result
# callback.
#
# The output for a successful task is the result of the task.
# The output for a failed task is the original input task definition.
TaskResult Callbacks Map:
# Sample input:
# {
# Job: { Id: "123" },
# Execution: { Id: "a1b2c3" },
# Artifact: {…},
# TaskIndex: 1/2/3/etc,
# Task: {…},
# Callbacks: {…},
# TaskResult: { Task: "___SOME_TASK_TYPE___", …other_task_fields },
# }
# Sample output: (will become an element in TasksMapResults)
# { Task: "___SOME_TASK_TYPE___", …other_result_fields }
Type: Map
QueryLanguage: JSONPath
Comment: >-
Iterates over all callback endpoints to send messages when tasks
are successful
# Add the result of the Map (an array containing the results of each iteration) to the default output
ResultPath: "$.TaskResultCallbacksMapResultNulls"
# Use the TaskResult as the final output of this iteration
OutputPath: "$.TaskResult"
End: true
MaxConcurrency: 0
ItemsPath: "$.Callbacks" # This references post-InputPath input
ItemSelector: # Initial state for each ItemProcessor iteration
Callback.$: "$$.Map.Item.Value"
StateMachine:
Id.$: "$$.StateMachine.Id"
Execution:
Id.$: "$$.Execution.Id"
TaskIteratorIndex.$: "$.TaskIndex"
Message: # The callbacks Lambda function uses the JSON of this value as the message sent to each callback
Task.$: "$.Task"
TaskResult: # The `TaskResult` field MUST be included in these callback messages per our published API
Job:
Id.$: "$.Job.Id"
Execution:
Id.$: "$$.Execution.Id"
Result.$: "$.TaskResult"
ItemProcessor:
ProcessorConfig: { Mode: INLINE }
StartAt: Send TaskResult Callback
States:
Send TaskResult Callback:
# Sample input: See map's ItemSelector
# Sample output: (will become an element in TaskResultCallbacksMapResultNulls)
# null
Type: Task
Comment: >-
Sends a callback message to a single endpoint when tasks
are successful
Retry:
- { ErrorEquals: [States.ALL], IntervalSeconds: 5, MaxAttempts: 3, BackoffRate: 2 }
Resource: "${CallbackLambdaFunctionArn}"
End: true
TaskResult Error Callback Map:
# Sample input:
# {
# Job: { Id: "123" },
# Execution: { Id: "a1b2c3" },
# Artifact: {…},
# TaskIndex: 1/2/3/etc,
# Task: {…},
# Callbacks: {…},
# Error: {…},
# }
# Sample output: (will become an element in TasksMapResults)
# { Type: "___SOME_TASK_TYPE___", …other_task_fields }
Type: Map
QueryLanguage: JSONPath
Comment: >-
Iterates over all callback endpoints to send messages when tasks
fail
# Add the result of the Map (an array containing the results of each iteration) to the default output
ResultPath: "$.TaskResultErrorCallbacksMapResultNulls"
# Use the Task as the final output of this iteration
OutputPath: "$.Task"
End: true
MaxConcurrency: 0
ItemsPath: "$.Callbacks" # This references post-InputPath input
ItemSelector: # Initial state for each ItemProcessor iteration
Callback.$: "$$.Map.Item.Value"
StateMachine:
Id.$: "$$.StateMachine.Id"
Execution:
Id.$: "$$.Execution.Id"
TaskIteratorIndex.$: "$.TaskIndex"
Message: # The JSON of this value will be sent to endpoints
Task.$: "$.Task"
TaskResult: # The `TaskResult` field MUST be included in these callback messages per our published API
Job:
Id.$: "$.Job.Id"
Execution:
Id.$: "$$.Execution.Id"
# $.Error will exist when a state takes the Catch path (because
# of `ResultPath: "$.Error"`) and will generally be an object
# like:
# { Error: "SomeError", Cause: "Something went wrong" }
Error.$: "$.Error"
ItemProcessor:
ProcessorConfig: { Mode: INLINE }
StartAt: Send TaskResult Error Callback
States:
Send TaskResult Error Callback:
# Sample input: See map's ItemSelector
# Sample output: (will become an element in TaskResultErrorCallbacksMapResultNulls)
# null
Type: Task
Comment: >-
Sends a callback message to a single endpoint when tasks
fail
Retry:
- { ErrorEquals: [States.ALL], IntervalSeconds: 5, MaxAttempts: 3, BackoffRate: 2 }
Resource: "${CallbackLambdaFunctionArn}"
End: true
Tasks Map Catcher:
# This state generally doesn't come into play if a task within the Task Map fails, as those failures are caught
# within the map itself. Certain conditions can cause the Tasks Map state to fail hard enough to end up here,
# though.
#
# Sample input:
# {
# Job: { Id: "123", Source: {…}, Tasks: […], Callbacks: […], SerializedJobs: […], ExecutionTrace: […] },
# State: "DONE",
# Artifact: { Descriptor: {…} },
# Error: {…}
# }
# Sample output:
# {
# Job: { Id: "123", Source: {…}, Tasks: […], Callbacks: […], SerializedJobs: […], ExecutionTrace: […] },
# State: "ITERATOR_ERROR",
# Artifact: { Descriptor: {…} },
# Error: {…}
# }
Type: Pass
QueryLanguage: JSONPath
Comment: >-
Add a field so task map errors can be identified. Is NOT responsible
for catching individual task execution errors (like if a Copy task fails)