aws / aws/aws-cdk

stepfunctions: associateWithParent should place id alongside existing input

Open
#31,788 2 comments 0 reactions 0 assignees View on GitHub
@aws-cdk/aws-stepfunctions effort/medium feature-request p2
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 3h
Merged PRs (30d)
83

Description

### Describe the feature

The `associateWithParent` flag should add a token to the existing payload when no input specified.

*State input:*
```json
{
"prop1": "value1",
"props2-299": "...",
"prop300": "value300"
}
```
*associateWithParent:*
```json
{
"AWS_STEP_FUNCTIONS_STARTED_BY_EXECUTION_ID": "idhere",
"prop1": "value1",
"props2-299": "...",
"prop300": "value300"
}
```

### Use Case

There is a significant amount of extra states needed to pass the original input with the `AWS_STEP_FUNCTIONS_STARTED_BY_EXECUTION_ID` id to a StartExecution call. This makes it difficult to keep state machines compartmentalized.

Imagine I have two state machines.
State Machine `"Alpha"` which is called by hundreds of services. It takes an object with several hundred fields.
State Machine `"Beta"` which calls `Alpha`.

With the current functionality you cannot use `associateWithParent` at all, because of the way that Paths work. You'd need to specify each and every field from the original input which would be impossible to maintain. Instead you have to modify `Beta` to have two extra `Pass` states. The first `Pass` creates a new payload with two separate nested fields, the original input and the executionId. Then the second takes and merges these top level fields and then filters the output.

*Pass 1:*
```kotlin
stateName = "Get the Execution ID"
parameters = mapOf(
"json1" to mapOf("AWS_STEP_FUNCTIONS_STARTED_BY_EXECUTION_ID" to JsonPath.getExecutionId()),
"json2.$" to "$"
)
```
*Pass 2:*
```kotlin
parameters = mutableMapOf(
"output.$" to "States.JsonMerge($.json1, $.json2, false)"
)
outputPath = "$.output"
```

I'm not sure why you would ever need the current functionality, which is to completely erase the existing payload and replace it with the `AWS_STEP_FUNCTIONS_STARTED_BY_EXECUTION_ID`. It seems like it would be impossible to actually pass any data to your State Machine. I can understand wanting to _filter_ the output and place it directly alongside the execution id. No other CDK Step Function construct works this way, where if the input is not specified then the input is entirely erased and it is very confusing when you activate `associateWithParent` and suddenly your input is erased and replaced with a token you would expect to appear alongside your input.

### Proposed Solution

If an `input` (TaskInput) is not specified then it should just place the `AWS_STEP_FUNCTIONS_STARTED_BY_EXECUTION_ID` directly alongside the existing task input. The task input should not be nested below another key.

Turning on `associateWithParent` should do this to the input:

```json
{
"param1": "value1"
}
```

to

```json
{
"AWS_STEP_FUNCTIONS_STARTED_BY_EXECUTION_ID": "idhere",
"param1": "value1"
}
```

NOT this:

```json
{
"AWS_STEP_FUNCTIONS_STARTED_BY_EXECUTION_ID": "idhere"
}
```

If a TaskInput is specified in the `input` property then that should follow the existing documentation around adding fields to the input.

### Other Information

_No response_

### Acknowledgements

- [ ] I may be able to implement this feature request
- [X] This feature might incur a breaking change

### CDK version used

software.amazon.awscdk:aws-cdk-lib:2.158.0

### Environment details (OS name and version, etc.)

macOS Sonoma 14.7

Contributor guide

Open the contributing guide

Research direction

Start by locating the aws-stepfunctions implementation and tests for the associateWithParent option and its TaskInput handling. Verify the current behavior when no input is specified, then define completion as preserving the existing task payload while placing AWS_STEP_FUNCTIONS_STARTED_BY_EXECUTION_ID alongside it, without changing the behavior for an explicitly supplied TaskInput.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, typescript
Domain
backend, cloud
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.