こんにちは、CX事業本部 Delivery部の若槻です。
本日リリースされた AWS CDK v2.90.0 で Step Functions ステートマシン の L2 Construct に comment
プロパティが設定可能になりました。
stepfunctions: allow setting comment on state machine (#25858) (6a70b4f)
そんなに大きいアップデートでは無さそうですが、Step Functions という推し機能のアップデートということで、早速試してみたいと思います。
試してみる
モジュールのアップデート
AWS CDK のモジュールを v2.90.0 以上にアップグレードします。
npm i aws-cdk@latest aws-cdk-lib@latest
CDK コード
AWS CDK のコードです。次のように StateMachine
L2 Construct に comment
プロパティを指定できるようになっています。
lib/cdk-sample-stack.ts
import { aws_stepfunctions, Stack, StackProps } 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);
new aws_stepfunctions.StateMachine(this, 'MyStateMachine', {
definitionBody: aws_stepfunctions.DefinitionBody.fromChainable(
new aws_stepfunctions.Pass(this, 'MyPassState', {})
),
comment: 'My first CDK state machine',
});
}
}
スタックをデプロイします。
cdk deploy
そもそもステートマシンに comment
というプロパティは、無い
さて、comment
プロパティを指定したので、マネジメントコンソール上で情報として確認できるようになったかと思いきや、そのような記載は見当たりませんね。
そこで今回のスタックの CloudFormation テンプレートを確認してみても、こちらにも comment
というプロパティは見当たりません。
$ cdk synth
Resources:
MyStateMachineRoleD59FFEBC:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Statement:
- Action: sts:AssumeRole
Effect: Allow
Principal:
Service: states.amazonaws.com
Version: "2012-10-17"
Metadata:
aws:cdk:path: CdkSampleStack/MyStateMachine/Role/Resource
MyStateMachine6C968CA5:
Type: AWS::StepFunctions::StateMachine
Properties:
DefinitionString: '{"StartAt":"MyPassState","States":{"MyPassState":{"Type":"Pass","End":true}},"Comment":"My first CDK state machine"}'
RoleArn:
Fn::GetAtt:
- MyStateMachineRoleD59FFEBC
- Arn
DependsOn:
- MyStateMachineRoleD59FFEBC
UpdateReplacePolicy: Delete
DeletionPolicy: Delete
Metadata:
aws:cdk:path: CdkSampleStack/MyStateMachine/Resource
CDKMetadata:
Type: AWS::CDK::Metadata
Properties:
Analytics: v2:deflate64:H4sIAAAAAAAA/02OvQ7CMBCDn4U9OVoWYO6MhMoDoJBcxfXnUvUSGKK8OyldOtn+LFk+wbWC6mC+oq0b9EgvSI9g7KAKeiYJOHeRbSDPAuluRFSpA96MfROjajre56zITJBaP/6rVXNWLYqPi93QzjeeHa3TWbF3CL0cP/UF6nN51AuRXiIHmhDaTX9AnpJZrQAAAA==
Metadata:
aws:cdk:path: CdkSampleStack/CDKMetadata/Default
Condition: CDKMetadataAvailable
Conditions:
CDKMetadataAvailable:
Fn::Or:
- Fn::Or:
- Fn::Equals:
- Ref: AWS::Region
- af-south-1
- Fn::Equals:
- Ref: AWS::Region
- ap-east-1
- Fn::Equals:
- Ref: AWS::Region
- ap-northeast-1
- Fn::Equals:
- Ref: AWS::Region
- ap-northeast-2
- Fn::Equals:
- Ref: AWS::Region
- ap-south-1
- Fn::Equals:
- Ref: AWS::Region
- ap-southeast-1
- Fn::Equals:
- Ref: AWS::Region
- ap-southeast-2
- Fn::Equals:
- Ref: AWS::Region
- ca-central-1
- Fn::Equals:
- Ref: AWS::Region
- cn-north-1
- Fn::Equals:
- Ref: AWS::Region
- cn-northwest-1
- Fn::Or:
- Fn::Equals:
- Ref: AWS::Region
- eu-central-1
- Fn::Equals:
- Ref: AWS::Region
- eu-north-1
- Fn::Equals:
- Ref: AWS::Region
- eu-south-1
- Fn::Equals:
- Ref: AWS::Region
- eu-west-1
- Fn::Equals:
- Ref: AWS::Region
- eu-west-2
- Fn::Equals:
- Ref: AWS::Region
- eu-west-3
- Fn::Equals:
- Ref: AWS::Region
- me-south-1
- Fn::Equals:
- Ref: AWS::Region
- sa-east-1
- Fn::Equals:
- Ref: AWS::Region
- us-east-1
- Fn::Equals:
- Ref: AWS::Region
- us-east-2
- Fn::Or:
- Fn::Equals:
- Ref: AWS::Region
- us-west-1
- Fn::Equals:
- Ref: AWS::Region
- us-west-2
Parameters:
BootstrapVersion:
Type: AWS::SSM::Parameter::Value<String>
Default: /cdk-bootstrap/hnb659fds/version
Description: Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]
Rules:
CheckBootstrapVersion:
Assertions:
- Assert:
Fn::Not:
- Fn::Contains:
- - "1"
- "2"
- "3"
- "4"
- "5"
- Ref: BootstrapVersion
AssertDescription: CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI.
そうなんです。そもそもステートマシンに comment
というプロパティは無いのです。
本機能の Pull Rquest を見ても、このcomment
プロパティの具体的な使い方については特に言及がありませんでした。
よって、今回使用可能になったcomment
プロパティは、CDK 上でステートマシンのコメント記述するためのみのプロパティとなるようです。
おわりに
AWS CDK v2.90.0 で Step Functions ステートマシン の L2 Construct に comment
プロパティが設定可能になったので試してみました。
Lambda Fcuntion でいう description
に該当するプロパティがついに Step Functions でも利用可能になったのかと思ったのですが、そもそもステートマシンにそのようなプロパティは存在せず、CDK 上でのみ使えるというものでした。なので、純粋に CDK コード上でコメントとして使用するか、なにかしらの目的で Construct を抽出する処理を行いたい場合に使用することになるかと思います。
以上