Skip to content

StepFunctionsStartExecution: Cannot pass Task Token using sfn.TaskInput.fromText #34189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
1 task
luiscarlosjayk opened this issue Apr 17, 2025 · 1 comment
Open
1 task
Labels
@aws-cdk/aws-stepfunctions Related to AWS StepFunctions bug This issue is a bug. effort/medium Medium work item – several days of effort p2

Comments

@luiscarlosjayk
Copy link

Describe the bug

I'm not able to write more complex jsonata exression that allows me to pass the TaskToken merged with other values within a same object for the input of the StepFunctionsStartExecution when the jsonata static method is used.

public static containsTaskToken(obj?: { [key: string]: any }): boolean {

If I use

tasks.StepFunctionsStartExecution.jsonata(this, 'StartAnotherSFN', {
    stateMachine: otherSFNReference,
    associateWithParent: true,
    integrationPattern: sfn.IntegrationPattern.WAIT_FOR_TASK_TOKEN,
    taskTimeout: sfn.Timeout.duration(cdk.Duration.minutes(1)),
    input: sfn.TaskInput.fromObject({
        token: '{% $states.context.Task.Token %}',
    }),
});

it works, but if try to use instead:

input: sfn.TaskInput.fromText(`{%
        "token": $states.context.Task.Token
%}`),

it doesn't.

And I needed to use sfn.TaskInput.fromText because I needed to use $merge method from jsonata to construct a more complex object.

Regression Issue

  • Select this option if this issue appears to be a regression.

Last Known Working CDK Version

No response

Expected Behavior

I expected this to work:

tasks.StepFunctionsStartExecution.jsonata(this, 'StartAnotherSFN', {
            stateMachine: otherSFNReference,
            associateWithParent: true,
            integrationPattern: sfn.IntegrationPattern.WAIT_FOR_TASK_TOKEN,
            taskTimeout: sfn.Timeout.duration(cdk.Duration.minutes(1)),
            input: sfn.TaskInput.fromText(`{%
                "token": $states.context.Task.Token
            %}`),
});

Current Behavior

I get an error:
Error: Task Token is required in input for callback. Use JsonPath.taskToken to set the token.

Reproduction Steps

Try to use the StepFunctionsStartExecution task to call another step function with waitForTaskToken integration pattern and use sfn.TaskInput.fromText instead of fromObject to pass the Task Token.

Possible Solution

Revisit the regex pattern.

Additional Information/Context

No response

CDK CLI Version

2.190.0

Framework Version

No response

Node.js Version

22.14.0

OS

MacOS

Language

TypeScript

Language Version

5.8.3

Other information

No response

@luiscarlosjayk luiscarlosjayk added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Apr 17, 2025
@github-actions github-actions bot added the @aws-cdk/aws-stepfunctions Related to AWS StepFunctions label Apr 17, 2025
@luiscarlosjayk luiscarlosjayk changed the title (module name): (short issue description) StepFunctionsStartExecution: Cannot pass Task Token using sfn.TaskInput.fromText Apr 17, 2025
@pahud
Copy link
Contributor

pahud commented Apr 18, 2025

Current vs Expected

Image

Hi @luiscarlosjayk,

Thank you for reporting this issue and providing detailed steps to reproduce.
You are right—currently, the CDK checks for the presence of the Task Token in your input using FieldUtils.containsTaskToken, but this check may not reliably detect the token if you use more advanced jsonata expressions or string templates inside TaskInput.fromText.

Why this happens:
The constructor for StepFunctionsStartExecution throws if it can't confirm that the Task Token is present in the input, which is required for the WAIT_FOR_TASK_TOKEN pattern.
If your string template or jsonata-based input is not detected by the check, you'll see the error.

Possible workaround:
For now, use TaskInput.fromObject({ token: '{% $states.context.Task.Token %}', ... }) if you can. If you must build up more complex objects, consider doing so programmatically before passing them to fromObject. Ensure that the string {% $states.context.Task.Token %} appears unambiguously in the input object.

Framework improvement:
It would be beneficial to enhance containsTaskToken to better recognize embedded task tokens in advanced inputs.
Would you be interested in helping improve this detection logic? Contributions are welcome! You can find the relevant function here.

Thanks again for your feedback and please let us know if you have further questions.
PRs are always welcome!

@pahud pahud added p2 effort/medium Medium work item – several days of effort and removed needs-triage This issue or PR still needs to be triaged. labels Apr 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-stepfunctions Related to AWS StepFunctions bug This issue is a bug. effort/medium Medium work item – several days of effort p2
Projects
None yet
Development

No branches or pull requests

2 participants