# 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 › WaiterStateMachine
Implements: IConstruct, IDependable

- Source: [`custom-resources/lib/provider-framework/waiter-state-machine.ts`](https://github.com/aws/aws-cdk/blob/v2.274.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

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

## Initializer

```ts
new WaiterStateMachine(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](/cdk/api/v2/docs/aws-cdk-lib.Duration.html) (required) — The interval to wait between attempts.

- `isCompleteHandler`: [IFunction](/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](/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](/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](/cdk/api/v2/docs/constructs.Node.html) (required) — The tree node.

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

- `stateMachineArn`: string (required) — 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
