# 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.

Extends: [Construct](https://docs.aws.amazon.com/cdk/api/v2/docs/constructs.Construct.html) › WaiterStateMachine
Implements: [IConstruct](https://docs.aws.amazon.com/cdk/api/v2/docs/constructs.IConstruct.html), [IDependable](https://docs.aws.amazon.com/cdk/api/v2/docs/constructs.IDependable.html)

- Source: [`custom-resources/lib/provider-framework/waiter-state-machine.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/custom-resources/lib/provider-framework/waiter-state-machine.ts#L90)
- Type last changed: v2.196.0 · 16 May 2025

## Example

TypeScript:

```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:

```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:

```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();
```

C# / .NET:

```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
    }
});
```

Golang:

```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

TypeScript:

```ts
new WaiterStateMachine(scope: Construct, id: string, props: WaiterStateMachineProps)
```

Python:

```python
WaiterStateMachine(scope: Construct, id: str, props: WaiterStateMachineProps)
```

Java:

```java
new WaiterStateMachine(Construct scope, String id, WaiterStateMachineProps props)
```

C# / .NET:

```csharp
new WaiterStateMachine(Construct scope, string id, WaiterStateMachineProps props)
```

Golang:

```go
NewWaiterStateMachine(Scope Construct, Id *string, Props WaiterStateMachineProps)
```

## Construct Props

- `backoffRate`: number (required) — Backoff between attempts.

- `disableLogging`: boolean = false — Whether logging for the state machine is disabled.

- `interval`: [Duration](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.Duration.html) (required) — The interval to wait between attempts.

- `isCompleteHandler`: [IFunction](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.IFunction.html) (required) — The main handler that notifies if the waiter to decide 'complete' or 'incomplete'.

- `logOptions`: [LogOptions](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.custom_resources.LogOptions.html) — Defines what execution history events are logged and where they are logged.

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

- `maxAttempts`: number (required) — Number of attempts.

- `timeoutHandler`: [IFunction](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.IFunction.html) (required) — The handler to call if the waiter times out and is incomplete.

## Properties

- `node`: [Node](https://docs.aws.amazon.com/cdk/api/v2/docs/constructs.Node.html) — The tree node.

- `PROPERTY_INJECTION_ID`: string (static) — Uniquely identifies this class.

- `stateMachineArn`: string — The ARN of the state machine.

## Methods

- `grantStartExecution(identity: IGrantable): Grant` — Grant the given identity permissions on StartExecution of the state machine.

  [disable-awslint:no-grants]

- `isConstruct(x: any): boolean` (static) — Checks if `x` is a construct.

  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**

  - `x` — Any object.

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

- `toString(): string` — Returns a string representation of this construct.

- `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.

  **Parameters**

  - `mixins` — The mixins to apply.

  **Returns:** This construct for chaining
