aws / aws/aws-cdk

aws-stepfunctions: Map/DMap Followed by Choice Rule Fails to Create Depending on Next State Ordering

Open
#29,238 3 comments 0 reactions 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

When creating a `Map` or `DistributedMap` construct with its `itemProcessor` pointing to a `Choice` state, it is possible for the generated state machine definition to be invalid depending on the order of the `Next` assignments of the `Choice` state's next state transitions.

e.g. Given:

```typescript
choicey
.when(sfn.Condition.isPresent('$.timeToChoose'), passy)
.otherwise(otherPassy);
```

This following it will succeed:

```typescript
otherPassy.next(finalPassy);
passy.next(finalPassy);
```

While this following it will fail:

```typescript
passy.next(finalPassy);
otherPassy.next(finalPassy);
```

### Expected Behavior

The state machine should create successfully

### Current Behavior

Throws

```bash
Invalid State Machine Definition: 'MISSING_TRANSITION_TARGET: Missing 'Next' target: Pass 2 at /States/My Mappy/ItemProcessor/States/It is time to choose/Default
```

### Reproduction Steps

```typescript
import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as sfn from 'aws-cdk-lib/aws-stepfunctions';

export class CdkStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);

const passy = new sfn.Pass(this, 'Pass 1', {});

const otherPassy = new sfn.Pass(this, 'Pass 2', {});
const finalPassy = new sfn.Pass(this, 'Pass 3', {});

const mappy = new sfn.Map(this, 'My Mappy', {});
const choicey = new sfn.Choice(this, 'It is time to choose');
mappy.itemProcessor(choicey);

choicey
.when(sfn.Condition.isPresent('$.timeToChoose'), passy)
.otherwise(otherPassy);


passy.next(finalPassy); // If this is set first
otherPassy.next(finalPassy); // and this is set second

// this will fail to create
new sfn.StateMachine(this, 'StateMachine', {
definition: sfn.Chain.start(mappy)
});

}
}
```

### Possible Solution

_No response_

### Additional Information/Context

_No response_

### CDK CLI Version

2.129.0

### Framework Version

_No response_

### Node.js Version

v21.6.2

### OS

Mac 14.3.1

### Language

TypeScript

### Language Version

_No response_

### Other information

_No response_

Contributor guide

Open the contributing guide

Research direction

The reproduction uses Map.itemProcessor, Choice.when/otherwise, Pass.next, and StateMachine definition, but names no source files or tests. First reproduce the failure with the supplied TypeScript example, then trace state-definition generation for Choice transitions inside Map and add regression coverage proving either Next assignment order creates a valid state machine.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.