Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(stepfunctions): allow setting comment on state machine #25858

Merged
merged 2 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"version": "30.0.0",
"version": "32.0.0",
"files": {
"c7c4e7caf8e5f2d81a89f6af62c998e0ca5ce879824d7b7c64264944911a7178": {
"2b683032648fa932811d781e11acb71f29e8dcde21411e7cf232807cc2565770": {
"source": {
"path": "aws-stepfunctions-integ.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "c7c4e7caf8e5f2d81a89f6af62c998e0ca5ce879824d7b7c64264944911a7178.json",
"objectKey": "2b683032648fa932811d781e11acb71f29e8dcde21411e7cf232807cc2565770.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
"Arn"
]
},
"DefinitionString": "{\"StartAt\":\"wait time\",\"States\":{\"wait time\":{\"Type\":\"Wait\",\"SecondsPath\":\"$.waitSeconds\",\"End\":true}}}"
"DefinitionString": "{\"StartAt\":\"wait time\",\"States\":{\"wait time\":{\"Type\":\"Wait\",\"SecondsPath\":\"$.waitSeconds\",\"End\":true}},\"Comment\":\"a super cool state machine\"}"
},
"DependsOn": [
"StateMachineRoleB840431D"
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version":"30.0.0"}
{"version":"32.0.0"}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "30.0.0",
"version": "32.0.0",
"testCases": {
"integ.state-machine": {
"stacks": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "30.0.0",
"version": "32.0.0",
"artifacts": {
"aws-stepfunctions-integ.assets": {
"type": "cdk:asset-manifest",
Expand All @@ -17,7 +17,7 @@
"validateOnSynth": false,
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}",
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/c7c4e7caf8e5f2d81a89f6af62c998e0ca5ce879824d7b7c64264944911a7178.json",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/2b683032648fa932811d781e11acb71f29e8dcde21411e7cf232807cc2565770.json",
"requiresBootstrapStackVersion": 6,
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
"additionalDependencies": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"id": "wait time",
"path": "aws-stepfunctions-integ/wait time",
"constructInfo": {
"fqn": "@aws-cdk/aws-stepfunctions.Wait",
"fqn": "aws-cdk-lib.aws_stepfunctions.Wait",
"version": "0.0.0"
}
},
Expand All @@ -24,7 +24,7 @@
"id": "ImportRole",
"path": "aws-stepfunctions-integ/Role/ImportRole",
"constructInfo": {
"fqn": "@aws-cdk/core.Resource",
"fqn": "aws-cdk-lib.Resource",
"version": "0.0.0"
}
},
Expand All @@ -49,7 +49,7 @@
}
},
"constructInfo": {
"fqn": "@aws-cdk/aws-iam.CfnRole",
"fqn": "aws-cdk-lib.aws_iam.CfnRole",
"version": "0.0.0"
}
},
Expand Down Expand Up @@ -139,19 +139,19 @@
}
},
"constructInfo": {
"fqn": "@aws-cdk/aws-iam.CfnPolicy",
"fqn": "aws-cdk-lib.aws_iam.CfnPolicy",
"version": "0.0.0"
}
}
},
"constructInfo": {
"fqn": "@aws-cdk/aws-iam.Policy",
"fqn": "aws-cdk-lib.aws_iam.Policy",
"version": "0.0.0"
}
}
},
"constructInfo": {
"fqn": "@aws-cdk/aws-iam.Role",
"fqn": "aws-cdk-lib.aws_iam.Role",
"version": "0.0.0"
}
},
Expand All @@ -167,7 +167,7 @@
"id": "ImportRole",
"path": "aws-stepfunctions-integ/StateMachine/Role/ImportRole",
"constructInfo": {
"fqn": "@aws-cdk/core.Resource",
"fqn": "aws-cdk-lib.Resource",
"version": "0.0.0"
}
},
Expand All @@ -192,13 +192,13 @@
}
},
"constructInfo": {
"fqn": "@aws-cdk/aws-iam.CfnRole",
"fqn": "aws-cdk-lib.aws_iam.CfnRole",
"version": "0.0.0"
}
}
},
"constructInfo": {
"fqn": "@aws-cdk/aws-iam.Role",
"fqn": "aws-cdk-lib.aws_iam.Role",
"version": "0.0.0"
}
},
Expand All @@ -214,39 +214,39 @@
"Arn"
]
},
"definitionString": "{\"StartAt\":\"wait time\",\"States\":{\"wait time\":{\"Type\":\"Wait\",\"SecondsPath\":\"$.waitSeconds\",\"End\":true}}}"
"definitionString": "{\"StartAt\":\"wait time\",\"States\":{\"wait time\":{\"Type\":\"Wait\",\"SecondsPath\":\"$.waitSeconds\",\"End\":true}},\"Comment\":\"a super cool state machine\"}"
}
},
"constructInfo": {
"fqn": "@aws-cdk/aws-stepfunctions.CfnStateMachine",
"fqn": "aws-cdk-lib.aws_stepfunctions.CfnStateMachine",
"version": "0.0.0"
}
}
},
"constructInfo": {
"fqn": "@aws-cdk/aws-stepfunctions.StateMachine",
"fqn": "aws-cdk-lib.aws_stepfunctions.StateMachine",
"version": "0.0.0"
}
},
"BootstrapVersion": {
"id": "BootstrapVersion",
"path": "aws-stepfunctions-integ/BootstrapVersion",
"constructInfo": {
"fqn": "@aws-cdk/core.CfnParameter",
"fqn": "aws-cdk-lib.CfnParameter",
"version": "0.0.0"
}
},
"CheckBootstrapVersion": {
"id": "CheckBootstrapVersion",
"path": "aws-stepfunctions-integ/CheckBootstrapVersion",
"constructInfo": {
"fqn": "@aws-cdk/core.CfnRule",
"fqn": "aws-cdk-lib.CfnRule",
"version": "0.0.0"
}
}
},
"constructInfo": {
"fqn": "@aws-cdk/core.Stack",
"fqn": "aws-cdk-lib.Stack",
"version": "0.0.0"
}
},
Expand All @@ -255,12 +255,12 @@
"path": "Tree",
"constructInfo": {
"fqn": "constructs.Construct",
"version": "10.1.237"
"version": "10.2.26"
}
}
},
"constructInfo": {
"fqn": "@aws-cdk/core.App",
"fqn": "aws-cdk-lib.App",
"version": "0.0.0"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const role = new iam.Role(stack, 'Role', {

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

stateMachine.grantRead(role);
Expand Down
2 changes: 2 additions & 0 deletions packages/aws-cdk-lib/aws-stepfunctions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const definition = submitJob
new sfn.StateMachine(this, 'StateMachine', {
definition,
timeout: Duration.minutes(5),
comment: 'a super cool state machine',
});
```

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

// don't forget permissions. You need to assign them
Expand Down
10 changes: 9 additions & 1 deletion packages/aws-cdk-lib/aws-stepfunctions/lib/state-machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@ export interface StateMachineProps {
*/
readonly timeout?: Duration;

/**
* Comment that describes this state machine
*
* @default - No comment
*/
readonly comment?: string;

/**
* Type of the state machine
*
Expand Down Expand Up @@ -711,8 +718,9 @@ export class ChainDefinitionBody extends DefinitionBody {
for (const statement of graph.policyStatements) {
sfnPrincipal.addToPrincipalPolicy(statement);
}
const graphJson = graph.toGraphJson();
return {
definitionString: Stack.of(scope).toJsonString(graph.toGraphJson()),
definitionString: Stack.of(scope).toJsonString({ ...graphJson, Comment: sfnProps.comment }),
};
}
}
21 changes: 21 additions & 0 deletions packages/aws-cdk-lib/aws-stepfunctions/test/state-machine.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,27 @@ describe('State Machine', () => {

}),

test('Instantiate Standard State Machine With Comment', () => {
// GIVEN
const stack = new cdk.Stack();

// WHEN
new sfn.StateMachine(stack, 'MyStateMachine', {
stateMachineName: 'MyStateMachine',
definition: sfn.Chain.start(new sfn.Pass(stack, 'Pass')),
stateMachineType: sfn.StateMachineType.STANDARD,
comment: 'zorp',
});

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::StepFunctions::StateMachine', {
StateMachineName: 'MyStateMachine',
StateMachineType: 'STANDARD',
DefinitionString: '{"StartAt":"Pass","States":{"Pass":{"Type":"Pass","End":true}},"Comment":"zorp"}',
});

}),

test('Instantiate Express State Machine', () => {
// GIVEN
const stack = new cdk.Stack();
Expand Down