Class Choice
Define a Choice in the state machine.
Inherited Members
Namespace: Amazon.CDK.AWS.StepFunctions
Assembly: Amazon.CDK.AWS.StepFunctions.dll
Syntax (csharp)
public class Choice : State, IConstruct, IDependable, IChainable
Syntax (vb)
Public Class Choice
Inherits State
Implements IConstruct, IDependable, IChainable
Remarks
A choice state can be used to make decisions based on the execution state.
ExampleMetadata: infused
Examples
using Amazon.CDK.AWS.Lambda;
Function submitLambda;
Function getStatusLambda;
var submitJob = new LambdaInvoke(this, "Submit Job", new LambdaInvokeProps {
LambdaFunction = submitLambda,
// Lambda's result is in the attribute `Payload`
OutputPath = "$.Payload"
});
var waitX = new Wait(this, "Wait X Seconds", new WaitProps {
Time = WaitTime.SecondsPath("$.waitSeconds")
});
var getStatus = new LambdaInvoke(this, "Get Job Status", new LambdaInvokeProps {
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"
});
var jobFailed = new Fail(this, "Job Failed", new FailProps {
Cause = "AWS Batch Job Failed",
Error = "DescribeJob returned FAILED"
});
var finalStatus = new LambdaInvoke(this, "Get Final Job Status", new LambdaInvokeProps {
LambdaFunction = getStatusLambda,
// Use "guid" field as input
InputPath = "$.guid",
OutputPath = "$.Payload"
});
var 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));
new StateMachine(this, "StateMachine", new StateMachineProps {
Definition = definition,
Timeout = Duration.Minutes(5)
});
Synopsis
Constructors
Choice(ByRefValue) | Used by jsii to construct an instance of this class from a Javascript-owned object reference |
Choice(DeputyBase.DeputyProps) | Used by jsii to construct an instance of this class from DeputyProps |
Choice(Construct, String, IChoiceProps) |
Properties
EndStates | Continuable states of this Chainable. |
Methods
Afterwards(IAfterwardsOptions) | Return a Chain that contains all reachable end states from this Choice. |
Otherwise(IChainable) | If none of the given conditions match, continue execution with the given state. |
ToStateJson() | Return the Amazon States Language object for this state. |
When(Condition, IChainable) | If the given condition matches, continue execution with the given state. |
Constructors
Choice(ByRefValue)
Used by jsii to construct an instance of this class from a Javascript-owned object reference
protected Choice(ByRefValue reference)
Parameters
- reference Amazon.JSII.Runtime.Deputy.ByRefValue
The Javascript-owned object reference
Choice(DeputyBase.DeputyProps)
Used by jsii to construct an instance of this class from DeputyProps
protected Choice(DeputyBase.DeputyProps props)
Parameters
- props Amazon.JSII.Runtime.Deputy.DeputyBase.DeputyProps
The deputy props
Choice(Construct, String, IChoiceProps)
public Choice(Construct scope, string id, IChoiceProps props = null)
Parameters
- scope Constructs.Construct
- id System.String
- props IChoiceProps
Properties
EndStates
Continuable states of this Chainable.
public override INextable[] EndStates { get; }
Property Value
Overrides
Methods
Afterwards(IAfterwardsOptions)
Return a Chain that contains all reachable end states from this Choice.
public virtual Chain Afterwards(IAfterwardsOptions options = null)
Parameters
- options IAfterwardsOptions
Returns
Remarks
Use this to combine all possible choice paths back.
Otherwise(IChainable)
If none of the given conditions match, continue execution with the given state.
public virtual Choice Otherwise(IChainable def)
Parameters
- def IChainable
Returns
Remarks
If no conditions match and no otherwise() has been given, an execution error will be raised.
ToStateJson()
Return the Amazon States Language object for this state.
public override JObject ToStateJson()
Returns
Newtonsoft.Json.Linq.JObject
Overrides
When(Condition, IChainable)
If the given condition matches, continue execution with the given state.
public virtual Choice When(Condition condition, IChainable next)
Parameters
- condition Condition
- next IChainable
Returns