Skip to content
v2.274.0

WaiterStateMachine ​

A very simple StateMachine construct highly customized to the provider framework.

We previously used CfnResource instead of CfnStateMachine to avoid depending on aws-stepfunctions module, but now it is okay.

The state machine continuously calls the isCompleteHandler, until it succeeds or times out. The handler is called maxAttempts times with an interval duration and a backoffRate rate.

Example ​

ts
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import * as cdk from 'aws-cdk-lib';
import { aws_lambda as lambda } from 'aws-cdk-lib';
import { aws_stepfunctions as stepfunctions } from 'aws-cdk-lib';
import { custom_resources } from 'aws-cdk-lib';
import { aws_logs as interfaces_logs } from 'aws-cdk-lib/interfaces';

declare const function_: lambda.Function;
declare const logGroupRef: interfaces_logs.ILogGroupRef;
const waiterStateMachine = new custom_resources.WaiterStateMachine(this, 'MyWaiterStateMachine', {
  backoffRate: 123,
  interval: cdk.Duration.minutes(30),
  isCompleteHandler: function_,
  maxAttempts: 123,
  timeoutHandler: function_,

  // the properties below are optional
  disableLogging: false,
  logOptions: {
    destination: logGroupRef,
    includeExecutionData: false,
    level: stepfunctions.LogLevel.OFF,
  },
});
python
# The code below shows an example of how to instantiate this type.
# The values are placeholders you should change.
import aws_cdk as cdk
from aws_cdk import aws_lambda as lambda_
from aws_cdk import aws_stepfunctions as stepfunctions
from aws_cdk import custom_resources
from aws_cdk.interfaces import aws_logs as interfaces_logs

# function_: lambda.Function
# log_group_ref: interfaces_logs.ILogGroupRef

waiter_state_machine = custom_resources.WaiterStateMachine(self, "MyWaiterStateMachine",
    backoff_rate=123,
    interval=cdk.Duration.minutes(30),
    is_complete_handler=function_,
    max_attempts=123,
    timeout_handler=function_,

    # the properties below are optional
    disable_logging=False,
    log_options=custom_resources.LogOptions(
        destination=log_group_ref,
        include_execution_data=False,
        level=stepfunctions.LogLevel.OFF
    )
)
java
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import software.amazon.awscdk.*;
import software.amazon.awscdk.services.lambda.*;
import software.amazon.awscdk.services.stepfunctions.*;
import software.amazon.awscdk.customresources.*;
import software.amazon.awscdk.interfaces.logs.*;

Function function_;
ILogGroupRef logGroupRef;

WaiterStateMachine waiterStateMachine = WaiterStateMachine.Builder.create(this, "MyWaiterStateMachine")
        .backoffRate(123)
        .interval(Duration.minutes(30))
        .isCompleteHandler(function_)
        .maxAttempts(123)
        .timeoutHandler(function_)

        // the properties below are optional
        .disableLogging(false)
        .logOptions(LogOptions.builder()
                .destination(logGroupRef)
                .includeExecutionData(false)
                .level(LogLevel.OFF)
                .build())
        .build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
using Amazon.CDK;
using Amazon.CDK.AWS.Lambda;
using Amazon.CDK.AWS.StepFunctions;
using Amazon.CDK.CustomResources;
using Amazon.CDK.Interfaces.Logs;

Function function_;
ILogGroupRef logGroupRef;

var waiterStateMachine = new WaiterStateMachine(this, "MyWaiterStateMachine", new WaiterStateMachineProps {
    BackoffRate = 123,
    Interval = Duration.Minutes(30),
    IsCompleteHandler = function_,
    MaxAttempts = 123,
    TimeoutHandler = function_,

    // the properties below are optional
    DisableLogging = false,
    LogOptions = new LogOptions {
        Destination = logGroupRef,
        IncludeExecutionData = false,
        Level = LogLevel.OFF
    }
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import cdk "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"

var function_ Function
var logGroupRef ILogGroupRef

waiterStateMachine := awscdk.Custom_resources.NewWaiterStateMachine(this, jsii.String("MyWaiterStateMachine"), &WaiterStateMachineProps{
	BackoffRate: jsii.Number(123),
	Interval: cdk.Duration_Minutes(jsii.Number(30)),
	IsCompleteHandler: function_,
	MaxAttempts: jsii.Number(123),
	TimeoutHandler: function_,

	// the properties below are optional
	DisableLogging: jsii.Boolean(false),
	LogOptions: &LogOptions{
		Destination: logGroupRef,
		IncludeExecutionData: jsii.Boolean(false),
		Level: awscdk.Aws_stepfunctions.LogLevel_OFF,
	},
})

Initializer ​

ts
new WaiterStateMachine(scope: Construct, id: string, props: WaiterStateMachineProps)
python
WaiterStateMachine(scope: Construct, id: str, props: WaiterStateMachineProps)
java
new WaiterStateMachine(Construct scope, String id, WaiterStateMachineProps props)
csharp
new WaiterStateMachine(Construct scope, string id, WaiterStateMachineProps props)
go
NewWaiterStateMachine(Scope Construct, Id *string, Props WaiterStateMachineProps)

Construct Props ​

backoffRatenumberbackoff_rateint | floatbackoffRateNumberBackoffRatedoubleBackoffRate*float64required#
Backoff between attempts.
disableLoggingbooleandisable_loggingbooldisableLoggingBooleanDisableLoggingboolDisableLogging*bool= false#
Whether logging for the state machine is disabled.
intervalDurationintervalDurationintervalDurationIntervalDurationIntervalDurationrequired#
The interval to wait between attempts.
isCompleteHandlerIFunctionis_complete_handlerIFunctionisCompleteHandlerIFunctionIsCompleteHandlerIFunctionIsCompleteHandlerIFunctionrequired#
The main handler that notifies if the waiter to decide 'complete' or 'incomplete'.
logOptionsLogOptionslog_optionsLogOptionslogOptionsLogOptionsLogOptionsLogOptionsLogOptionsLogOptions#
Defines what execution history events are logged and where they are logged.

Default: A default log group will be created if logging is enabled.

maxAttemptsnumbermax_attemptsint | floatmaxAttemptsNumberMaxAttemptsdoubleMaxAttempts*float64required#
Number of attempts.
timeoutHandlerIFunctiontimeout_handlerIFunctiontimeoutHandlerIFunctionTimeoutHandlerIFunctionTimeoutHandlerIFunctionrequired#
The handler to call if the waiter times out and is incomplete.

Properties ​

nodeNodenodeNodenodeNodeNodeNodeNodeNoderequired#
The tree node.
PROPERTY_INJECTION_IDstringproperty_injection_idstrPROPERTY_INJECTION_IDStringPROPERTY_INJECTION_IDstringPROPERTY_INJECTION_ID*stringrequiredstatic#
Uniquely identifies this class.
stateMachineArnstringstate_machine_arnstrstateMachineArnStringStateMachineArnstringStateMachineArn*stringrequired#
The ARN of the state machine.

Methods ​

grantStartExecution(identity: IGrantable): Grantdef grant_start_execution(self, identity: IGrantable) -> Grantpublic Grant grantStartExecution(IGrantable identity)public Grant GrantStartExecution(IGrantable identity)func GrantStartExecution(Identity IGrantable) Grant#
Grant the given identity permissions on StartExecution of the state machine.

[disable-awslint:no-grants]

isConstruct(x: any): boolean@staticmethod def is_construct(x: Any) -> boolpublic static Boolean isConstruct(Object x)public static bool IsConstruct(object x)func IsConstruct(X interface{}) *boolstatic#
Checks if `x` is a construct.
notes · 1 parameter · returns

Use this method instead of instanceof to properly detect Construct instances, even when the construct library is symlinked.

Explanation: in JavaScript, multiple copies of the constructs library on disk are seen as independent, completely different libraries. As a consequence, the class Construct in each copy of the constructs library is seen as a different class, and an instance of one class will not test as instanceof the other class. npm install will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the constructs library can be accidentally installed, and instanceof will behave unpredictably. It is safest to avoid using instanceof, and using this type-testing method instead.

Parameters

  • xxxxX — Any object.

Returns: true if x is an object created from a class which extends Construct.

toString(): stringdef to_string(self, ) -> strpublic String toString()public string ToString()func ToString() *string#
Returns a string representation of this construct.
with(...mixins: IMixin[]): IConstructdef with(self, mixins: IMixin) -> IConstructpublic IConstruct with(IMixin mixins)public IConstruct With(IMixin mixins)func With(Mixins IMixin) IConstruct#
Applies one or more mixins to this construct.

Mixins are applied in order. The list of constructs is captured at the start of the call, so constructs added by a mixin will not be visited. Use multiple with() calls if subsequent mixins should apply to added constructs.

1 parameter · returns

Parameters

  • mixinsmixinsmixinsmixinsMixins — The mixins to apply.

Returns: This construct for chaining