java.lang.Object
software.amazon.jsii.JsiiObject
software.constructs.Construct
All Implemented Interfaces:
IConstruct, IDependable, IChainable, software.amazon.jsii.JsiiSerializable, software.constructs.IConstruct

@Generated(value="jsii-pacmak/1.84.0 (build 5404dcf)", date="2023-06-19T16:30:39.896Z") @Stability(Stable) public class Choice extends State
Define a Choice in the state machine.

A choice state can be used to make decisions based on the execution state.

Example:

 import software.amazon.awscdk.services.lambda.*;
 Function submitLambda;
 Function getStatusLambda;
 LambdaInvoke submitJob = LambdaInvoke.Builder.create(this, "Submit Job")
         .lambdaFunction(submitLambda)
         // Lambda's result is in the attribute `Payload`
         .outputPath("$.Payload")
         .build();
 Wait waitX = Wait.Builder.create(this, "Wait X Seconds")
         .time(WaitTime.secondsPath("$.waitSeconds"))
         .build();
 LambdaInvoke getStatus = LambdaInvoke.Builder.create(this, "Get Job Status")
         .lambdaFunction(getStatusLambda)
         // Pass just the field named "guid" into the Lambda, put the
         // Lambda's result in a field called "status" in the response
         .inputPath("$.guid")
         .outputPath("$.Payload")
         .build();
 Fail jobFailed = Fail.Builder.create(this, "Job Failed")
         .cause("AWS Batch Job Failed")
         .error("DescribeJob returned FAILED")
         .build();
 LambdaInvoke finalStatus = LambdaInvoke.Builder.create(this, "Get Final Job Status")
         .lambdaFunction(getStatusLambda)
         // Use "guid" field as input
         .inputPath("$.guid")
         .outputPath("$.Payload")
         .build();
 Chain definition = submitJob.next(waitX).next(getStatus).next(new Choice(this, "Job Complete?").when(Condition.stringEquals("$.status", "FAILED"), jobFailed).when(Condition.stringEquals("$.status", "SUCCEEDED"), finalStatus).otherwise(waitX));
 StateMachine.Builder.create(this, "StateMachine")
         .definition(definition)
         .timeout(Duration.minutes(5))
         .build();
 
  • Constructor Details

    • Choice

      protected Choice(software.amazon.jsii.JsiiObjectRef objRef)
    • Choice

      protected Choice(software.amazon.jsii.JsiiObject.InitializationMode initializationMode)
    • Choice

      @Stability(Stable) public Choice(@NotNull software.constructs.Construct scope, @NotNull String id, @Nullable ChoiceProps props)
      Parameters:
      scope - This parameter is required.
      id - This parameter is required.
      props -
    • Choice

      @Stability(Stable) public Choice(@NotNull software.constructs.Construct scope, @NotNull String id)
      Parameters:
      scope - This parameter is required.
      id - This parameter is required.
  • Method Details

    • afterwards

      @Stability(Stable) @NotNull public Chain afterwards(@Nullable AfterwardsOptions options)
      Return a Chain that contains all reachable end states from this Choice.

      Use this to combine all possible choice paths back.

      Parameters:
      options -
    • afterwards

      @Stability(Stable) @NotNull public Chain afterwards()
      Return a Chain that contains all reachable end states from this Choice.

      Use this to combine all possible choice paths back.

    • otherwise

      @Stability(Stable) @NotNull public Choice otherwise(@NotNull IChainable def)
      If none of the given conditions match, continue execution with the given state.

      If no conditions match and no otherwise() has been given, an execution error will be raised.

      Parameters:
      def - This parameter is required.
    • toStateJson

      @Stability(Stable) @NotNull public com.fasterxml.jackson.databind.node.ObjectNode toStateJson()
      Return the Amazon States Language object for this state.
      Specified by:
      toStateJson in class State
    • when

      @Stability(Stable) @NotNull public Choice when(@NotNull Condition condition, @NotNull IChainable next)
      If the given condition matches, continue execution with the given state.

      Parameters:
      condition - This parameter is required.
      next - This parameter is required.
    • getEndStates

      @Stability(Stable) @NotNull public List<INextable> getEndStates()
      Continuable states of this Chainable.
      Specified by:
      getEndStates in interface IChainable
      Specified by:
      getEndStates in class State