class Choice (construct)
Language | Type name |
---|---|
![]() | Amazon.CDK.AWS.StepFunctions.Choice |
![]() | github.com/aws/aws-cdk-go/awscdk/v2/awsstepfunctions#Choice |
![]() | software.amazon.awscdk.services.stepfunctions.Choice |
![]() | aws_cdk.aws_stepfunctions.Choice |
![]() | aws-cdk-lib » aws_stepfunctions » Choice |
Implements
IConstruct
, IDependable
, IChainable
Define a Choice in the state machine.
A choice state can be used to make decisions based on the execution state.
Example
const map = new sfn.Map(this, 'Map State', {
maxConcurrency: 1,
itemsPath: sfn.JsonPath.stringAt('$.inputForMap'),
itemSelector: {
item: sfn.JsonPath.stringAt('$$.Map.Item.Value'),
},
resultPath: '$.mapOutput',
});
// The Map iterator can contain a IChainable, which can be an individual or multiple steps chained together.
// Below example is with a Choice and Pass step
const choice = new sfn.Choice(this, 'Choice');
const condition1 = sfn.Condition.stringEquals('$.item.status', 'SUCCESS');
const step1 = new sfn.Pass(this, 'Step1');
const step2 = new sfn.Pass(this, 'Step2');
const finish = new sfn.Pass(this, 'Finish');
const definition = choice
.when(condition1, step1)
.otherwise(step2)
.afterwards()
.next(finish);
map.itemProcessor(definition);
Initializer
new Choice(scope: Construct, id: string, props?: ChoiceProps)
Parameters
- scope
Construct
- id
string
— Descriptive identifier for this chainable. - props
Choice
Props
Construct Props
Name | Type | Description |
---|---|---|
assign? | { [string]: any } | Workflow variables to store in this step. |
comment? | string | A comment describing this state. |
input | string | JSONPath expression to select part of the state to be the input to this state. |
output | string | JSONPath expression to select part of the state to be the output to this state. |
outputs? | any | Used to specify and transform output from the state. |
query | Query | The name of the query language used by the state. |
state | string | Optional name for this state. |
assign?
Type:
{ [string]: any }
(optional, default: Not assign variables)
Workflow variables to store in this step.
Using workflow variables, you can store data in a step and retrieve that data in future steps.
comment?
Type:
string
(optional, default: No comment)
A comment describing this state.
inputPath?
Type:
string
(optional, default: $)
JSONPath expression to select part of the state to be the input to this state.
May also be the special value JsonPath.DISCARD, which will cause the effective input to be the empty object {}.
outputPath?
Type:
string
(optional, default: $)
JSONPath expression to select part of the state to be the output to this state.
May also be the special value JsonPath.DISCARD, which will cause the effective output to be the empty object {}.
outputs?
Type:
any
(optional, default: $states.result or $states.errorOutput)
Used to specify and transform output from the state.
When specified, the value overrides the state output default. The output field accepts any JSON value (object, array, string, number, boolean, null). Any string value, including those inside objects or arrays, will be evaluated as JSONata if surrounded by {% %} characters. Output also accepts a JSONata expression directly.
queryLanguage?
Type:
Query
(optional, default: JSONPath)
The name of the query language used by the state.
If the state does not contain a queryLanguage
field,
then it will use the query language specified in the top-level queryLanguage
field.
stateName?
Type:
string
(optional, default: The construct ID will be used as state name)
Optional name for this state.
Properties
Name | Type | Description |
---|---|---|
end | INextable [] | Continuable states of this Chainable. |
id | string | Descriptive identifier for this chainable. |
node | Node | The tree node. |
start | State | First state of this Chainable. |
state | string | Tokenized string that evaluates to the state's ID. |
endStates
Type:
INextable
[]
Continuable states of this Chainable.
id
Type:
string
Descriptive identifier for this chainable.
node
Type:
Node
The tree node.
startState
Type:
State
First state of this Chainable.
stateId
Type:
string
Tokenized string that evaluates to the state's ID.
Methods
Name | Description |
---|---|
add | Add a prefix to the stateId of this state. |
afterwards(options?) | Return a Chain that contains all reachable end states from this Choice. |
bind | Register this state as part of the given graph. |
otherwise(def) | If none of the given conditions match, continue execution with the given state. |
to | Return the Amazon States Language object for this state. |
to | Returns a string representation of this construct. |
when(condition, next, options?) | If the given condition matches, continue execution with the given state. |
static json | Define a Choice using JSONPath in the state machine. |
static jsonata(scope, id, props?) | Define a Choice using JSONata in the state machine. |
addPrefix(x)
public addPrefix(x: string): void
Parameters
- x
string
Add a prefix to the stateId of this state.
afterwards(options?)
public afterwards(options?: AfterwardsOptions): Chain
Parameters
- options
Afterwards
Options
Returns
Return a Chain that contains all reachable end states from this Choice.
Use this to combine all possible choice paths back.
bindToGraph(graph)
public bindToGraph(graph: StateGraph): void
Parameters
- graph
State
Graph
Register this state as part of the given graph.
Don't call this. It will be called automatically when you work with states normally.
otherwise(def)
public otherwise(def: IChainable): Choice
Parameters
- def
IChainable
Returns
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.
toStateJson(topLevelQueryLanguage?)
public toStateJson(topLevelQueryLanguage?: QueryLanguage): json
Parameters
- topLevelQueryLanguage
Query
Language
Returns
json
Return the Amazon States Language object for this state.
toString()
public toString(): string
Returns
string
Returns a string representation of this construct.
when(condition, next, options?)
public when(condition: Condition, next: IChainable, options?: ChoiceTransitionOptions): Choice
Parameters
- condition
Condition
- next
IChainable
- options
Choice
Transition Options
Returns
If the given condition matches, continue execution with the given state.
static jsonPath(scope, id, props?)
public static jsonPath(scope: Construct, id: string, props?: ChoiceJsonPathProps): Choice
Parameters
- scope
Construct
- id
string
- props
Choice
Json Path Props
Returns
Define a Choice using JSONPath in the state machine.
A choice state can be used to make decisions based on the execution state.
static jsonata(scope, id, props?)
public static jsonata(scope: Construct, id: string, props?: ChoiceJsonataProps): Choice
Parameters
- scope
Construct
- id
string
- props
Choice
Jsonata Props
Returns
Define a Choice using JSONata in the state machine.
A choice state can be used to make decisions based on the execution state.