Skip to content

"Wait for Callback" does not provide a Task.Token in the contact for all actions.

0

I am trying to build a step function workflow around transcribing audio files in an S3 bucket. This has worked great so far, but with smaller numbers of files. The job run I am trying to do now involves ~18K files, and so I am trying to improve the step function so that it'll wait for the transcription job to complete before scheduling more so I can control how many are submitted to Amazon Transcribe.

To accomplish that I checked the "Wait for Callback" on the StartTranscriptionJob action and am attempting to pass that value through to that call (in a Tag). However, this does not work as the $states.context does not have the Task.Token property set at all, thus the value cannot be forwarded along. (I have an eventbus setup that watches for transcribe state changes and calls the SendStepSuccess API)..

So, is this a bug in that action? or some bug in the JSONata implementation? or something else?

Here is the step itself, and the evaluation for TaskCallbackToken's "Value" always yields an error as $states.context.Task.Token is undefined.

"StartTranscriptionJob": {
            "Type": "Task",
            "Arguments": {
              "Media": {
                "MediaFileUri": "{% $join(['s3://', $Bucket,'/', $states.input.Key]) %}"
              },
              "LanguageCode": "en-US",
              "OutputBucketName": "{% $Bucket %}",
              "OutputKey": "{% $replace($states.input.Key, /\\/source\\/(.+)\\.(wav|mp4)/, '/output/$1.json') %}",
              "Settings": {
                "ShowSpeakerLabels": true,
                "MaxSpeakerLabels": 3
              },
              "TranscriptionJobName": "{% $join(['BatchTranscribe', $states.context.Execution.Name],'-') %}",
              "Tags": [
                {
                  "Key": "TaskCallbackToken",
                  "Value": "{% $states.context.Task.Token %}"
                },
                {
                  "Key": "Source",
                  "Value": "TriggerBatchTranscribe"
                }
              ]
            },
            "Resource": "arn:aws:states:::aws-sdk:transcribe:startTranscriptionJob.waitForTaskToken",
            "End": true
          }

asked a year ago246 views

2 Answers
0
Accepted Answer

I managed to figure out the issue. My MAP was utilizing the "Express" mode for iteration instead of Standard. Once I switch to Standard the token was generated and available in $states.context.Task.Token

answered a year ago

AWS
EXPERT

reviewed a year ago

0

The issue you're encountering is related to how the task token is accessed in the Wait for Callback pattern. When using the .waitForTaskToken integration pattern, you need to explicitly pass the task token using the $.Task.Token reference, not $states.context.Task.Token.

In your JSON configuration, you should modify the TaskCallbackToken Value to use the correct reference:

"Tags": [
{
"Key": "TaskCallbackToken",
"Value": "{% $.Task.Token %}"
},
{
"Key": "Source",
"Value": "TriggerBatchTranscribe"
}
]

The $.Task.Token is the correct way to access the task token from the Context object when using the Wait for Callback pattern. This token is what you'll need to return via the SendTaskSuccess or SendTaskFailure API calls to resume your workflow after the transcription job completes.

For the Wait for Callback pattern to work properly, you need to:

  1. Pass the task token to the service or external system
  2. Configure your EventBridge rule to capture the transcription job completion events
  3. Have your handler call SendTaskSuccess or SendTaskFailure with the token

This approach will allow your workflow to pause until each transcription job completes, giving you the control you need over how many jobs are submitted to Amazon Transcribe at once.
Sources
Troubleshooting issues in Step Functions - AWS Step Functions
Discover service integration patterns in Step Functions - AWS Step Functions

answered a year ago

  • This is actually completely incorrect. as it is pulling $.Task.Token from JSONPath which does not work in JSONata.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.