Skip to content
v2.277.0

WaitTime Class ​

Represents the Wait state which delays a state machine from continuing for a specified time.

Example ​

ts
const convertToSeconds = new tasks.EvaluateExpression(this, 'Convert to seconds', {
  expression: '$.waitMilliseconds / 1000',
  resultPath: '$.waitSeconds',
});

const createMessage = new tasks.EvaluateExpression(this, 'Create message', {
  // Note: this is a string inside a string.
  expression: '`Now waiting ${$.waitSeconds} seconds...`',
  runtime: lambda.Runtime.NODEJS_LATEST,
  resultPath: '$.message',
});

const publishMessage = new tasks.SnsPublish(this, 'Publish message', {
  topic: new sns.Topic(this, 'cool-topic'),
  message: sfn.TaskInput.fromJsonPathAt('$.message'),
  resultPath: '$.sns',
});

const wait = new sfn.Wait(this, 'Wait', {
  time: sfn.WaitTime.secondsPath('$.waitSeconds'),
});

new sfn.StateMachine(this, 'StateMachine', {
  definition: convertToSeconds
    .next(createMessage)
    .next(publishMessage)
    .next(wait),
});
python
convert_to_seconds = tasks.EvaluateExpression(self, "Convert to seconds",
    expression="$.waitMilliseconds / 1000",
    result_path="$.waitSeconds"
)

create_message = tasks.EvaluateExpression(self, "Create message",
    # Note: this is a string inside a string.
    expression="`Now waiting ${$.waitSeconds} seconds...`",
    runtime=lambda_.Runtime.NODEJS_LATEST,
    result_path="$.message"
)

publish_message = tasks.SnsPublish(self, "Publish message",
    topic=sns.Topic(self, "cool-topic"),
    message=sfn.TaskInput.from_json_path_at("$.message"),
    result_path="$.sns"
)

wait = sfn.Wait(self, "Wait",
    time=sfn.WaitTime.seconds_path("$.waitSeconds")
)

sfn.StateMachine(self, "StateMachine",
    definition=convert_to_seconds.next(create_message).next(publish_message).next(wait)
)
java
EvaluateExpression convertToSeconds = EvaluateExpression.Builder.create(this, "Convert to seconds")
        .expression("$.waitMilliseconds / 1000")
        .resultPath("$.waitSeconds")
        .build();

EvaluateExpression createMessage = EvaluateExpression.Builder.create(this, "Create message")
        // Note: this is a string inside a string.
        .expression("`Now waiting ${$.waitSeconds} seconds...`")
        .runtime(Runtime.NODEJS_LATEST)
        .resultPath("$.message")
        .build();

SnsPublish publishMessage = SnsPublish.Builder.create(this, "Publish message")
        .topic(new Topic(this, "cool-topic"))
        .message(TaskInput.fromJsonPathAt("$.message"))
        .resultPath("$.sns")
        .build();

Wait wait = Wait.Builder.create(this, "Wait")
        .time(WaitTime.secondsPath("$.waitSeconds"))
        .build();

StateMachine.Builder.create(this, "StateMachine")
        .definition(convertToSeconds.next(createMessage).next(publishMessage).next(wait))
        .build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
var convertToSeconds = new EvaluateExpression(this, "Convert to seconds", new EvaluateExpressionProps {
    Expression = "$.waitMilliseconds / 1000",
    ResultPath = "$.waitSeconds"
});

var createMessage = new EvaluateExpression(this, "Create message", new EvaluateExpressionProps {
    // Note: this is a string inside a string.
    Expression = "`Now waiting ${$.waitSeconds} seconds...`",
    Runtime = Runtime.NODEJS_LATEST,
    ResultPath = "$.message"
});

var publishMessage = new SnsPublish(this, "Publish message", new SnsPublishProps {
    Topic = new Topic(this, "cool-topic"),
    Message = TaskInput.FromJsonPathAt("$.message"),
    ResultPath = "$.sns"
});

var wait = new Wait(this, "Wait", new WaitProps {
    Time = WaitTime.SecondsPath("$.waitSeconds")
});

new StateMachine(this, "StateMachine", new StateMachineProps {
    Definition = convertToSeconds.Next(createMessage).Next(publishMessage).Next(wait)
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
convertToSeconds := tasks.NewEvaluateExpression(this, jsii.String("Convert to seconds"), &EvaluateExpressionProps{
	Expression: jsii.String("$.waitMilliseconds / 1000"),
	ResultPath: jsii.String("$.waitSeconds"),
})

createMessage := tasks.NewEvaluateExpression(this, jsii.String("Create message"), &EvaluateExpressionProps{
	// Note: this is a string inside a string.
	Expression: jsii.String("`Now waiting ${$.waitSeconds} seconds...`"),
	Runtime: lambda.Runtime_NODEJS_LATEST(),
	ResultPath: jsii.String("$.message"),
})

publishMessage := tasks.NewSnsPublish(this, jsii.String("Publish message"), &SnsPublishProps{
	Topic: sns.NewTopic(this, jsii.String("cool-topic")),
	Message: sfn.TaskInput_FromJsonPathAt(jsii.String("$.message")),
	ResultPath: jsii.String("$.sns"),
})

wait := sfn.NewWait(this, jsii.String("Wait"), &WaitProps{
	Time: sfn.WaitTime_SecondsPath(jsii.String("$.waitSeconds")),
})

sfn.NewStateMachine(this, jsii.String("StateMachine"), &StateMachineProps{
	Definition: convertToSeconds.Next(createMessage).Next(publishMessage).*Next(wait),
})

Methods ​

duration(duration: Duration): WaitTime // chainable@staticmethod def duration(duration: Duration) -> WaitTimepublic static WaitTime duration(Duration duration)public static WaitTime Duration(Duration duration)func Duration(Duration Duration) WaitTimestatic#
Wait a fixed amount of time.
seconds(seconds: string): WaitTime // chainable@staticmethod def seconds(seconds: str) -> WaitTimepublic static WaitTime seconds(String seconds)public static WaitTime Seconds(string seconds)func Seconds(Seconds *string) WaitTimestatic#
Wait for a number of seconds stored in the state object from string. This method can use JSONata expression.

If you want to use fixed value, we recommend using WaitTime.duration()

Example value: {% $waitSeconds %}

secondsPath(path: string): WaitTime // chainable@staticmethod def seconds_path(path: str) -> WaitTimepublic static WaitTime secondsPath(String path)public static WaitTime SecondsPath(string path)func SecondsPath(Path *string) WaitTimestatic#
Wait for a number of seconds stored in the state object.

Example value: $.waitSeconds

timestamp(timestamp: string): WaitTime // chainable@staticmethod def timestamp(timestamp: str) -> WaitTimepublic static WaitTime timestamp(String timestamp)public static WaitTime Timestamp(string timestamp)func Timestamp(Timestamp *string) WaitTimestatic#
Wait until the given ISO8601 timestamp. This method can use JSONata expression.

Example value: 2016-03-14T01:59:00Z

timestampPath(path: string): WaitTime // chainable@staticmethod def timestamp_path(path: str) -> WaitTimepublic static WaitTime timestampPath(String path)public static WaitTime TimestampPath(string path)func TimestampPath(Path *string) WaitTimestatic#
Wait until a timestamp found in the state object.

Example value: $.waitTimestamp