Skip to content

Commit 962fcbc

Browse files
author
Chelsea Urquhart
committed
feat(sfn): allow setting comment on state machine
1 parent 4240341 commit 962fcbc

File tree

4 files changed

+42
-0
lines changed

4 files changed

+42
-0
lines changed

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

+2
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ const definition = submitJob
5959
new sfn.StateMachine(this, 'StateMachine', {
6060
definition,
6161
timeout: Duration.minutes(5),
62+
comment: 'a super cool state machine',
6263
});
6364
```
6465

@@ -520,6 +521,7 @@ const chain = sfn.Chain.start(custom)
520521
const sm = new sfn.StateMachine(this, 'StateMachine', {
521522
definition: chain,
522523
timeout: Duration.seconds(30),
524+
comment: 'a super cool state machine',
523525
});
524526

525527
// don't forget permissions. You need to assign them

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

+11
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ export class StateGraph {
3535
*/
3636
public timeout?: Duration;
3737

38+
/**
39+
* Set a comment to render into the graph JSON.
40+
*
41+
* Read/write. Only makes sense on the top-level graph, subgraphs
42+
* do not support this feature.
43+
*
44+
* @default No comment
45+
*/
46+
public comment?: string;
47+
3848
/**
3949
* The accumulated policy statements
4050
*/
@@ -113,6 +123,7 @@ export class StateGraph {
113123
StartAt: this.startState.stateId,
114124
States: states,
115125
TimeoutSeconds: this.timeout && this.timeout.toSeconds(),
126+
Comment: this.comment,
116127
};
117128
}
118129

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

+8
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,13 @@ export interface StateMachineProps {
107107
*/
108108
readonly timeout?: Duration;
109109

110+
/**
111+
* Comment that describes this state machine
112+
*
113+
* @default No comment
114+
*/
115+
readonly comment?: string;
116+
110117
/**
111118
* Type of the state machine
112119
*
@@ -410,6 +417,7 @@ export class StateMachine extends StateMachineBase {
410417

411418
const graph = new StateGraph(props.definition.startState, `State Machine ${id} definition`);
412419
graph.timeout = props.timeout;
420+
graph.comment = props.comment;
413421

414422
this.stateMachineType = props.stateMachineType ?? StateMachineType.STANDARD;
415423

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

+21
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,27 @@ describe('State Machine', () => {
4444

4545
}),
4646

47+
test('Instantiate Standard State Machine With Comment', () => {
48+
// GIVEN
49+
const stack = new cdk.Stack();
50+
51+
// WHEN
52+
new sfn.StateMachine(stack, 'MyStateMachine', {
53+
stateMachineName: 'MyStateMachine',
54+
definition: sfn.Chain.start(new sfn.Pass(stack, 'Pass')),
55+
stateMachineType: sfn.StateMachineType.STANDARD,
56+
comment: 'zorp',
57+
});
58+
59+
// THEN
60+
Template.fromStack(stack).hasResourceProperties('AWS::StepFunctions::StateMachine', {
61+
StateMachineName: 'MyStateMachine',
62+
StateMachineType: 'STANDARD',
63+
DefinitionString: '{"StartAt":"Pass","States":{"Pass":{"Type":"Pass","End":true}},"Comment":"zorp"}',
64+
});
65+
66+
}),
67+
4768
test('Instantiate Express State Machine', () => {
4869
// GIVEN
4970
const stack = new cdk.Stack();

0 commit comments

Comments
 (0)