Skip to content

Commit 61be7a6

Browse files
authored
feat(stepfunctions): adding custom state name prop (#27306)
Closes #23532 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent beac675 commit 61be7a6

File tree

18 files changed

+168
-12
lines changed

18 files changed

+168
-12
lines changed

packages/aws-cdk-lib/aws-stepfunctions/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ becomes new the new Data object. This behavior can be modified by supplying valu
124124

125125
These properties impact how each individual step interacts with the state machine data:
126126

127+
* `stateName`: the name of the state in the state machine definition. If not supplied, defaults to the construct id.
127128
* `inputPath`: the part of the data object that gets passed to the step (`itemsPath` for `Map` states)
128129
* `resultSelector`: the part of the step result that should be added to the state machine data
129130
* `resultPath`: where in the state machine data the step result should be inserted
@@ -285,6 +286,7 @@ and also injects a field called `otherData`.
285286

286287
```ts
287288
const pass = new sfn.Pass(this, 'Filter input and inject data', {
289+
stateName: 'my-pass-state', // the custom state name for the Pass state, defaults to 'Filter input and inject data' as the state name
288290
parameters: { // input to the pass state
289291
input: sfn.JsonPath.stringAt('$.input.greeting'),
290292
otherData: 'some-extra-stuff',

packages/aws-cdk-lib/aws-stepfunctions/lib/state-machine.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export interface StateMachineProps {
101101
readonly definitionBody?: DefinitionBody;
102102

103103
/**
104-
* substitutions for the definition body aas a key-value map
104+
* substitutions for the definition body as a key-value map
105105
*/
106106
readonly definitionSubstitutions?: { [key: string]: string };
107107

packages/aws-cdk-lib/aws-stepfunctions/lib/states/choice.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ import { IChainable, INextable } from '../types';
99
* Properties for defining a Choice state
1010
*/
1111
export interface ChoiceProps {
12+
/**
13+
* Optional name for this state
14+
*
15+
* @default - The construct ID will be used as state name
16+
*/
17+
readonly stateName?: string;
18+
1219
/**
1320
* An optional description for this state
1421
*

packages/aws-cdk-lib/aws-stepfunctions/lib/states/fail.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ import { INextable } from '../types';
77
* Properties for defining a Fail state
88
*/
99
export interface FailProps {
10+
/**
11+
* Optional name for this state
12+
*
13+
* @default - The construct ID will be used as state name
14+
*/
15+
readonly stateName?: string;
16+
1017
/**
1118
* An optional description for this state
1219
*

packages/aws-cdk-lib/aws-stepfunctions/lib/states/map.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ import { CatchProps, IChainable, INextable, RetryProps } from '../types';
1111
* Properties for defining a Map state
1212
*/
1313
export interface MapProps {
14+
/**
15+
* Optional name for this state
16+
*
17+
* @default - The construct ID will be used as state name
18+
*/
19+
readonly stateName?: string;
20+
1421
/**
1522
* An optional description for this state
1623
*

packages/aws-cdk-lib/aws-stepfunctions/lib/states/parallel.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ import { CatchProps, IChainable, INextable, RetryProps } from '../types';
99
* Properties for defining a Parallel state
1010
*/
1111
export interface ParallelProps {
12+
/**
13+
* Optional name for this state
14+
*
15+
* @default - The construct ID will be used as state name
16+
*/
17+
readonly stateName?: string;
18+
1219
/**
1320
* An optional description for this state
1421
*

packages/aws-cdk-lib/aws-stepfunctions/lib/states/pass.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ export class Result {
5656
* Properties for defining a Pass state
5757
*/
5858
export interface PassProps {
59+
/**
60+
* Optional name for this state
61+
*
62+
* @default - The construct ID will be used as state name
63+
*/
64+
readonly stateName?: string;
65+
5966
/**
6067
* An optional description for this state
6168
*

packages/aws-cdk-lib/aws-stepfunctions/lib/states/state.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ import { CatchProps, Errors, IChainable, INextable, RetryProps } from '../types'
99
* Properties shared by all states
1010
*/
1111
export interface StateProps {
12+
/**
13+
* Optional name for this state
14+
*
15+
* @default - The construct ID will be used as state name
16+
*/
17+
readonly stateName?: string;
18+
1219
/**
1320
* A comment describing this state
1421
*
@@ -155,6 +162,7 @@ export abstract class State extends Construct implements IChainable {
155162
// features are shared by a couple of states, and it becomes cumbersome to
156163
// slice it out across all states. This is not great design, but it is
157164
// pragmatic!
165+
protected readonly stateName?: string;
158166
protected readonly comment?: string;
159167
protected readonly inputPath?: string;
160168
protected readonly parameters?: object;
@@ -194,6 +202,7 @@ export abstract class State extends Construct implements IChainable {
194202

195203
this.startState = this;
196204

205+
this.stateName = props.stateName;
197206
this.comment = props.comment;
198207
this.inputPath = props.inputPath;
199208
this.parameters = props.parameters;
@@ -219,7 +228,7 @@ export abstract class State extends Construct implements IChainable {
219228
* Tokenized string that evaluates to the state's ID
220229
*/
221230
public get stateId(): string {
222-
return this.prefixes.concat(this.id).join('');
231+
return this.prefixes.concat(this.stateName? this.stateName: this.id).join('');
223232
}
224233

225234
/**

packages/aws-cdk-lib/aws-stepfunctions/lib/states/succeed.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ import { INextable } from '../types';
77
* Properties for defining a Succeed state
88
*/
99
export interface SucceedProps {
10+
/**
11+
* Optional name for this state
12+
*
13+
* @default - The construct ID will be used as state name
14+
*/
15+
readonly stateName?: string;
16+
1017
/**
1118
* An optional description for this state
1219
*

packages/aws-cdk-lib/aws-stepfunctions/lib/states/task-base.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ import { CatchProps, IChainable, INextable, RetryProps } from '../types';
1313
* Props that are common to all tasks
1414
*/
1515
export interface TaskStateBaseProps {
16+
/**
17+
* Optional name for this state
18+
*
19+
* @default - The construct ID will be used as state name
20+
*/
21+
readonly stateName?: string;
22+
1623
/**
1724
* An optional description for this state
1825
*

0 commit comments

Comments
 (0)