aws / aws/aws-cdk

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

Open
#34,189 2 comments 1 reaction 0 assignees View on GitHub
@aws-cdk/aws-stepfunctions bug effort/medium p2
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 3h
Merged PRs (30d)
83

Description

### 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.

https://github.com/aws/aws-cdk/blob/0ad4f3bf108da86d6aa2087dcd8d51a999d5f51e/packages/aws-cdk-lib/aws-stepfunctions/lib/fields.ts#L521

If I use

```ts
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:

```ts
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:

```ts
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_

Contributor guide

Open the contributing guide

Research direction

Start with packages/aws-cdk-lib/aws-stepfunctions/lib/fields.ts at the linked code and reproduce the StepFunctionsStartExecution case using TaskInput.fromText with WAIT_FOR_TASK_TOKEN. Compare it with the working fromObject example and verify that the text form containing the JSONata task token is accepted without the missing-token error.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, typescript
Domain
cloud
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.