1- import { Fn , RemovalPolicy } from "aws-cdk-lib"
1+ import { RemovalPolicy } from "aws-cdk-lib"
22import {
33 IManagedPolicy ,
44 IRole ,
@@ -20,12 +20,22 @@ import {
2020} from "aws-cdk-lib/aws-stepfunctions"
2121import { Construct } from "constructs"
2222import { CfnDeliveryStream } from "aws-cdk-lib/aws-kinesisfirehose"
23+ import { ACCOUNT_RESOURCES , LAMBDA_RESOURCES } from "../constants"
2324
25+ /**
26+ * Configuration for provisioning an Express Step Functions state machine
27+ * with logging and optional Splunk forwarding.
28+ */
2429export interface StateMachineProps {
30+ /** Stack name, used as prefix for resource naming and DNS records. */
2531 readonly stackName : string
32+ /** Friendly state machine name used for both AWS resource and log naming. */
2633 readonly stateMachineName : string
34+ /** Workflow definition chain rendered as the state machine definition body. */
2735 readonly definition : IChainable
36+ /** Extra managed policies merged into the execution role when required. */
2837 readonly additionalPolicies ?: Array < IManagedPolicy >
38+ /** Retention period applied to the workflow CloudWatch log group. */
2939 readonly logRetentionInDays : number
3040 /**
3141 * Optional KMS key for encrypting CloudWatch Logs.
@@ -54,21 +64,40 @@ export interface StateMachineProps {
5464 readonly addSplunkSubscriptionFilter ?: boolean
5565}
5666
67+ /** Creates an Express Step Functions workflow with CloudWatch logging and invoke permissions. */
5768export class ExpressStateMachine extends Construct {
69+ /** Managed policy that grants permission to start this workflow. */
5870 public readonly executionPolicy : ManagedPolicy
71+
72+ /** Created Step Functions state machine resource. */
5973 public readonly stateMachine : StateMachine
6074
75+ /**
76+ * Provisions an Express Step Functions workflow with logging, tracing, and invoke permissions.
77+ * @example
78+ * ```ts
79+ * const sm = new ExpressStateMachine(this, "MyWorkflow", {
80+ * stackName: "my-service",
81+ * stateMachineName: "my-service-workflow",
82+ * definition: new Pass(this, "Start"),
83+ * logRetentionInDays: 30,
84+ * additionalPolicies: [myLambdaInvokePolicy]
85+ * })
86+ * // Attach the generated execution policy to an API Gateway role
87+ * apiGatewayRole.addManagedPolicy(sm.executionPolicy)
88+ * ```
89+ */
6190 public constructor ( scope : Construct , id : string , props : StateMachineProps ) {
6291 super ( scope , id )
6392
6493 const {
6594 cloudWatchLogsKmsKey = Key . fromKeyArn (
66- this , "CloudWatchLogsKmsKey" , Fn . importValue ( "account-resources: CloudwatchLogsKmsKeyArn" ) ) ,
95+ this , "CloudWatchLogsKmsKey" , ACCOUNT_RESOURCES . CloudwatchLogsKmsKeyArn ) ,
6796 cloudwatchEncryptionKMSPolicy = ManagedPolicy . fromManagedPolicyArn (
68- this , "cloudwatchEncryptionKMSPolicy" , Fn . importValue ( "account-resources: CloudwatchEncryptionKMSPolicyArn" ) ) ,
97+ this , "cloudwatchEncryptionKMSPolicy" , ACCOUNT_RESOURCES . CloudwatchEncryptionKMSPolicyArn ) ,
6998 splunkDeliveryStream,
7099 splunkSubscriptionFilterRole = Role . fromRoleArn (
71- this , "splunkSubscriptionFilterRole" , Fn . importValue ( "lambda-resources: SplunkSubscriptionFilterRole" ) ) ,
100+ this , "splunkSubscriptionFilterRole" , LAMBDA_RESOURCES . SplunkSubscriptionFilterRole ) ,
72101 addSplunkSubscriptionFilter = true
73102 } = props
74103
@@ -90,16 +119,16 @@ export class ExpressStateMachine extends Construct {
90119
91120 if ( addSplunkSubscriptionFilter ) {
92121 if ( splunkDeliveryStream ) {
93- new CfnSubscriptionFilter ( this , "LambdaLogsSplunkSubscriptionFilter " , {
122+ new CfnSubscriptionFilter ( this , "StateMachineLogsSplunkSubscriptionFilter " , {
94123 destinationArn : splunkDeliveryStream . attrArn ,
95124 filterPattern : "" ,
96125 logGroupName : logGroup . logGroupName ,
97126 roleArn : splunkSubscriptionFilterRole . roleArn
98127 } )
99128 } else {
100129 const splunkDeliveryStreamImport = Stream . fromStreamArn (
101- this , "SplunkDeliveryStream" , Fn . importValue ( "lambda-resources: SplunkDeliveryStream" ) )
102- new CfnSubscriptionFilter ( this , "LambdaLogsSplunkSubscriptionFilter " , {
130+ this , "SplunkDeliveryStream" , LAMBDA_RESOURCES . SplunkDeliveryStream )
131+ new CfnSubscriptionFilter ( this , "StateMachineLogsSplunkSubscriptionFilter " , {
103132 destinationArn : splunkDeliveryStreamImport . streamArn ,
104133 filterPattern : "" ,
105134 logGroupName : logGroup . logGroupName ,
@@ -118,7 +147,7 @@ export class ExpressStateMachine extends Construct {
118147 ] ,
119148 resources : [
120149 logGroup . logGroupArn ,
121- `${ logGroup . logGroupArn } :log-stream`
150+ `${ logGroup . logGroupArn } :log-stream:* `
122151 ]
123152 } ) ,
124153 new PolicyStatement ( {
0 commit comments