こんにちは、CX事業本部 Delivery部の若槻です。
AWS CDK v2.89.0 で Step Functions State Machine の L2 Construct に stateMachineRevisionId プロパティが追加され、取得可能になりました
stepfunctions: add stateMachineRevisionId property to StateMachine (#26443) (3e47d1b), closes #26440
stateMachineRevisionId は、State Machine の修正の識別子です。State Machine の修正が公開される際に内部的にこの値が更新されます。
ちなみに似ている概念としてこちらで紹介されている Versions and Aliases がありますが、別物となります。
試してみる
モジュールのアップデート
AWS CDK のモジュールを v2.89.0 以上にアップグレードします。
npm i aws-cdk aws-cdk-lib
stateMachineRevisionId の取得
まず AWS CDK で State Machine を初回作成します。aws_stepfunctions.StateMachine.stateMachineRevisionId
により stateMachineRevisionId を取得しています。
lib/cdk-sample-stack.ts
import { aws_stepfunctions, Stack, StackProps, CfnOutput } from 'aws-cdk-lib';
import { Construct } from 'constructs';
export class CdkSampleStack extends Stack {
public readonly myFileObjectKey: string;
constructor(scope: Construct, id: string, props: StackProps) {
super(scope, id, props);
const myStateMachine = new aws_stepfunctions.StateMachine(
this,
'MyStateMachine',
{
definitionBody: aws_stepfunctions.DefinitionBody.fromChainable(
new aws_stepfunctions.Pass(this, 'MyPassState', {})
),
}
);
new CfnOutput(this, 'myStateMachineRevisionId', {
value: myStateMachine.stateMachineRevisionId,
});
}
}
デプロイすると、初回作成なので INITIAL
という stateMachineRevisionId が取得できます。
$ cdk deploy
Outputs:
CdkSampleStack.myStateMachineRevisionId = INITIAL
次に State Machine を更新します。
lib/cdk-sample-stack.ts
{
definitionBody: aws_stepfunctions.DefinitionBody.fromChainable(
new aws_stepfunctions.Pass(this, 'MyPassState', {
resultPath: '$.result',
})
),
}
再度デプロイをすると、stateMachineRevisionId が更新されていることがわかります。
$ cdk deploy
Outputs:
CdkSampleStack.myStateMachineRevisionId = 30761163-8953-46d9-8d8e-d15ad223cc10
おわりに
AWS CDK v2.89.0 で Step Functions State Machine の L2 Construct に stateMachineRevisionId プロパティが追加され、取得可能になりました
これにより、今までは取得するために L1 Construct を使う必要があったところ、L2 Construct で完結できるようになりました。ただし、 stateMachineRevisionId を使って古いバージョンの State Machine 定義や構成を取得する方法は無さそうなため、ロールバックやリビジョン管理などに活用することも難しそうです。今回のアップデートの Issue を見ても、具体的なユースケースへの言及はありませんでした。内部的にこんなプロパティが使われているんだなという豆知識的なアップデートでした。
以上