From 5e127b2d1740cbf3092681399519c5ed3605f65f Mon Sep 17 00:00:00 2001 From: Adam Wong <55506708+wong-a@users.noreply.github.com> Date: Thu, 20 Jul 2023 11:45:29 -0700 Subject: [PATCH] feat(stepfunctions): add stateMachineRevisionId property to StateMachine (#26443) Expose `stateMachineRevisionId` as a readonly property to StateMachine whose value is a reference to the `StateMachineRevisionId` attribute of the underlying CloudFormation resource. Closes #26440 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- .../aws-stepfunctions/lib/state-machine.ts | 7 ++++++ .../test/state-machine.test.ts | 22 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/packages/aws-cdk-lib/aws-stepfunctions/lib/state-machine.ts b/packages/aws-cdk-lib/aws-stepfunctions/lib/state-machine.ts index 552a60d7c320e..e341239f62391 100644 --- a/packages/aws-cdk-lib/aws-stepfunctions/lib/state-machine.ts +++ b/packages/aws-cdk-lib/aws-stepfunctions/lib/state-machine.ts @@ -407,6 +407,12 @@ export class StateMachine extends StateMachineBase { */ public readonly stateMachineType: StateMachineType; + /** + * Identifier for the state machine revision, which is an immutable, read-only snapshot of a state machine’s definition and configuration. + * @attribute + */ + public readonly stateMachineRevisionId: string; + constructor(scope: Construct, id: string, props: StateMachineProps) { super(scope, id, { physicalName: props.stateMachineName, @@ -451,6 +457,7 @@ export class StateMachine extends StateMachineBase { resourceName: this.physicalName, arnFormat: ArnFormat.COLON_RESOURCE_NAME, }); + this.stateMachineRevisionId = resource.attrStateMachineRevisionId; } /** diff --git a/packages/aws-cdk-lib/aws-stepfunctions/test/state-machine.test.ts b/packages/aws-cdk-lib/aws-stepfunctions/test/state-machine.test.ts index 4dd9b3c374dde..7055ad2fad5d5 100644 --- a/packages/aws-cdk-lib/aws-stepfunctions/test/state-machine.test.ts +++ b/packages/aws-cdk-lib/aws-stepfunctions/test/state-machine.test.ts @@ -579,4 +579,26 @@ describe('State Machine', () => { DeletionPolicy: 'Retain', }); }); + + test('stateMachineRevisionId property uses attribute reference', () => { + // GIVEN + const stack = new cdk.Stack(); + + // WHEN + const stateMachine = new sfn.StateMachine(stack, 'MyStateMachine', { + stateMachineName: 'MyStateMachine', + definitionBody: sfn.DefinitionBody.fromChainable(new sfn.Pass(stack, 'Pass')), + }); + + new sfn.CfnStateMachineVersion(stack, 'MyStateMachineVersion', { + stateMachineRevisionId: stateMachine.stateMachineRevisionId, + stateMachineArn: stateMachine.stateMachineArn, + }); + + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::StepFunctions::StateMachineVersion', { + StateMachineArn: { Ref: 'MyStateMachine6C968CA5' }, + StateMachineRevisionId: { 'Fn::GetAtt': ['MyStateMachine6C968CA5', 'StateMachineRevisionId'] }, + }); + }); });