Skip to content

Commit 94a2dea

Browse files
author
Chelsea Urquhart
committed
feat(stepfunctions): allow setting comment on state machine
1 parent 6c588da commit 94a2dea

File tree

10 files changed

+58
-26
lines changed

10 files changed

+58
-26
lines changed

packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions/test/integ.state-machine.js.snapshot/aws-stepfunctions-integ.assets.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
{
2-
"version": "30.0.0",
2+
"version": "32.0.0",
33
"files": {
4-
"c7c4e7caf8e5f2d81a89f6af62c998e0ca5ce879824d7b7c64264944911a7178": {
4+
"2b683032648fa932811d781e11acb71f29e8dcde21411e7cf232807cc2565770": {
55
"source": {
66
"path": "aws-stepfunctions-integ.template.json",
77
"packaging": "file"
88
},
99
"destinations": {
1010
"current_account-current_region": {
1111
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
12-
"objectKey": "c7c4e7caf8e5f2d81a89f6af62c998e0ca5ce879824d7b7c64264944911a7178.json",
12+
"objectKey": "2b683032648fa932811d781e11acb71f29e8dcde21411e7cf232807cc2565770.json",
1313
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
1414
}
1515
}

packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions/test/integ.state-machine.js.snapshot/aws-stepfunctions-integ.template.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121
"Arn"
122122
]
123123
},
124-
"DefinitionString": "{\"StartAt\":\"wait time\",\"States\":{\"wait time\":{\"Type\":\"Wait\",\"SecondsPath\":\"$.waitSeconds\",\"End\":true}}}"
124+
"DefinitionString": "{\"StartAt\":\"wait time\",\"States\":{\"wait time\":{\"Type\":\"Wait\",\"SecondsPath\":\"$.waitSeconds\",\"End\":true}},\"Comment\":\"a super cool state machine\"}"
125125
},
126126
"DependsOn": [
127127
"StateMachineRoleB840431D"
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"version":"30.0.0"}
1+
{"version":"32.0.0"}

packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions/test/integ.state-machine.js.snapshot/integ.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "30.0.0",
2+
"version": "32.0.0",
33
"testCases": {
44
"integ.state-machine": {
55
"stacks": [

packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions/test/integ.state-machine.js.snapshot/manifest.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "30.0.0",
2+
"version": "32.0.0",
33
"artifacts": {
44
"aws-stepfunctions-integ.assets": {
55
"type": "cdk:asset-manifest",
@@ -17,7 +17,7 @@
1717
"validateOnSynth": false,
1818
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}",
1919
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}",
20-
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/c7c4e7caf8e5f2d81a89f6af62c998e0ca5ce879824d7b7c64264944911a7178.json",
20+
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/2b683032648fa932811d781e11acb71f29e8dcde21411e7cf232807cc2565770.json",
2121
"requiresBootstrapStackVersion": 6,
2222
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
2323
"additionalDependencies": [

packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions/test/integ.state-machine.js.snapshot/tree.json

+17-17
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"id": "wait time",
1313
"path": "aws-stepfunctions-integ/wait time",
1414
"constructInfo": {
15-
"fqn": "@aws-cdk/aws-stepfunctions.Wait",
15+
"fqn": "aws-cdk-lib.aws_stepfunctions.Wait",
1616
"version": "0.0.0"
1717
}
1818
},
@@ -24,7 +24,7 @@
2424
"id": "ImportRole",
2525
"path": "aws-stepfunctions-integ/Role/ImportRole",
2626
"constructInfo": {
27-
"fqn": "@aws-cdk/core.Resource",
27+
"fqn": "aws-cdk-lib.Resource",
2828
"version": "0.0.0"
2929
}
3030
},
@@ -49,7 +49,7 @@
4949
}
5050
},
5151
"constructInfo": {
52-
"fqn": "@aws-cdk/aws-iam.CfnRole",
52+
"fqn": "aws-cdk-lib.aws_iam.CfnRole",
5353
"version": "0.0.0"
5454
}
5555
},
@@ -139,19 +139,19 @@
139139
}
140140
},
141141
"constructInfo": {
142-
"fqn": "@aws-cdk/aws-iam.CfnPolicy",
142+
"fqn": "aws-cdk-lib.aws_iam.CfnPolicy",
143143
"version": "0.0.0"
144144
}
145145
}
146146
},
147147
"constructInfo": {
148-
"fqn": "@aws-cdk/aws-iam.Policy",
148+
"fqn": "aws-cdk-lib.aws_iam.Policy",
149149
"version": "0.0.0"
150150
}
151151
}
152152
},
153153
"constructInfo": {
154-
"fqn": "@aws-cdk/aws-iam.Role",
154+
"fqn": "aws-cdk-lib.aws_iam.Role",
155155
"version": "0.0.0"
156156
}
157157
},
@@ -167,7 +167,7 @@
167167
"id": "ImportRole",
168168
"path": "aws-stepfunctions-integ/StateMachine/Role/ImportRole",
169169
"constructInfo": {
170-
"fqn": "@aws-cdk/core.Resource",
170+
"fqn": "aws-cdk-lib.Resource",
171171
"version": "0.0.0"
172172
}
173173
},
@@ -192,13 +192,13 @@
192192
}
193193
},
194194
"constructInfo": {
195-
"fqn": "@aws-cdk/aws-iam.CfnRole",
195+
"fqn": "aws-cdk-lib.aws_iam.CfnRole",
196196
"version": "0.0.0"
197197
}
198198
}
199199
},
200200
"constructInfo": {
201-
"fqn": "@aws-cdk/aws-iam.Role",
201+
"fqn": "aws-cdk-lib.aws_iam.Role",
202202
"version": "0.0.0"
203203
}
204204
},
@@ -214,39 +214,39 @@
214214
"Arn"
215215
]
216216
},
217-
"definitionString": "{\"StartAt\":\"wait time\",\"States\":{\"wait time\":{\"Type\":\"Wait\",\"SecondsPath\":\"$.waitSeconds\",\"End\":true}}}"
217+
"definitionString": "{\"StartAt\":\"wait time\",\"States\":{\"wait time\":{\"Type\":\"Wait\",\"SecondsPath\":\"$.waitSeconds\",\"End\":true}},\"Comment\":\"a super cool state machine\"}"
218218
}
219219
},
220220
"constructInfo": {
221-
"fqn": "@aws-cdk/aws-stepfunctions.CfnStateMachine",
221+
"fqn": "aws-cdk-lib.aws_stepfunctions.CfnStateMachine",
222222
"version": "0.0.0"
223223
}
224224
}
225225
},
226226
"constructInfo": {
227-
"fqn": "@aws-cdk/aws-stepfunctions.StateMachine",
227+
"fqn": "aws-cdk-lib.aws_stepfunctions.StateMachine",
228228
"version": "0.0.0"
229229
}
230230
},
231231
"BootstrapVersion": {
232232
"id": "BootstrapVersion",
233233
"path": "aws-stepfunctions-integ/BootstrapVersion",
234234
"constructInfo": {
235-
"fqn": "@aws-cdk/core.CfnParameter",
235+
"fqn": "aws-cdk-lib.CfnParameter",
236236
"version": "0.0.0"
237237
}
238238
},
239239
"CheckBootstrapVersion": {
240240
"id": "CheckBootstrapVersion",
241241
"path": "aws-stepfunctions-integ/CheckBootstrapVersion",
242242
"constructInfo": {
243-
"fqn": "@aws-cdk/core.CfnRule",
243+
"fqn": "aws-cdk-lib.CfnRule",
244244
"version": "0.0.0"
245245
}
246246
}
247247
},
248248
"constructInfo": {
249-
"fqn": "@aws-cdk/core.Stack",
249+
"fqn": "aws-cdk-lib.Stack",
250250
"version": "0.0.0"
251251
}
252252
},
@@ -255,12 +255,12 @@
255255
"path": "Tree",
256256
"constructInfo": {
257257
"fqn": "constructs.Construct",
258-
"version": "10.1.237"
258+
"version": "10.2.26"
259259
}
260260
}
261261
},
262262
"constructInfo": {
263-
"fqn": "@aws-cdk/core.App",
263+
"fqn": "aws-cdk-lib.App",
264264
"version": "0.0.0"
265265
}
266266
}

packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions/test/integ.state-machine.ts

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const role = new iam.Role(stack, 'Role', {
2020

2121
const stateMachine = new sfn.StateMachine(stack, 'StateMachine', {
2222
definition: wait,
23+
comment: 'a super cool state machine',
2324
});
2425

2526
stateMachine.grantRead(role);

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

@@ -532,6 +533,7 @@ const chain = sfn.Chain.start(custom)
532533
const sm = new sfn.StateMachine(this, 'StateMachine', {
533534
definition: chain,
534535
timeout: Duration.seconds(30),
536+
comment: 'a super cool state machine',
535537
});
536538

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

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

+9-1
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,13 @@ export interface StateMachineProps {
119119
*/
120120
readonly timeout?: Duration;
121121

122+
/**
123+
* Comment that describes this state machine
124+
*
125+
* @default - No comment
126+
*/
127+
readonly comment?: string;
128+
122129
/**
123130
* Type of the state machine
124131
*
@@ -711,8 +718,9 @@ export class ChainDefinitionBody extends DefinitionBody {
711718
for (const statement of graph.policyStatements) {
712719
sfnPrincipal.addToPrincipalPolicy(statement);
713720
}
721+
const graphJson = graph.toGraphJson();
714722
return {
715-
definitionString: Stack.of(scope).toJsonString(graph.toGraphJson()),
723+
definitionString: Stack.of(scope).toJsonString({ ...graphJson, Comment: sfnProps.comment }),
716724
};
717725
}
718726
}

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

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

105105
}),
106106

107+
test('Instantiate Standard State Machine With Comment', () => {
108+
// GIVEN
109+
const stack = new cdk.Stack();
110+
111+
// WHEN
112+
new sfn.StateMachine(stack, 'MyStateMachine', {
113+
stateMachineName: 'MyStateMachine',
114+
definition: sfn.Chain.start(new sfn.Pass(stack, 'Pass')),
115+
stateMachineType: sfn.StateMachineType.STANDARD,
116+
comment: 'zorp',
117+
});
118+
119+
// THEN
120+
Template.fromStack(stack).hasResourceProperties('AWS::StepFunctions::StateMachine', {
121+
StateMachineName: 'MyStateMachine',
122+
StateMachineType: 'STANDARD',
123+
DefinitionString: '{"StartAt":"Pass","States":{"Pass":{"Type":"Pass","End":true}},"Comment":"zorp"}',
124+
});
125+
126+
}),
127+
107128
test('Instantiate Express State Machine', () => {
108129
// GIVEN
109130
const stack = new cdk.Stack();

0 commit comments

Comments
 (0)