ChoiceTransitionOptions Struct
Options for Choice Transition.
| Source | aws-stepfunctions/lib/states/state.ts |
|---|---|
| Type last changed |
Example
ts
import * as events from 'aws-cdk-lib/aws-events';
declare const connection: events.Connection;
const getIssue = tasks.HttpInvoke.jsonata(this, 'Get Issue', {
connection,
apiRoot: "{% 'https://' & $states.input.hostname %}",
apiEndpoint: sfn.TaskInput.fromText("{% 'issues/' & $states.input.issue.id %}"),
method: sfn.TaskInput.fromText('GET'),
// Parse the API call result to object and set to the variables
assign: {
hostname: '{% $states.input.hostname %}',
issue: '{% $parse($states.result.ResponseBody) %}',
},
});
const updateLabels = tasks.HttpInvoke.jsonata(this, 'Update Issue Labels', {
connection,
apiRoot: "{% 'https://' & $states.input.hostname %}",
apiEndpoint: sfn.TaskInput.fromText("{% 'issues/' & $states.input.issue.id & 'labels' %}"),
method: sfn.TaskInput.fromText('POST'),
body: sfn.TaskInput.fromObject({
labels: '{% [$type, $component] %}',
}),
});
const notMatchTitleTemplate = sfn.Pass.jsonata(this, 'Not Match Title Template');
const definition = getIssue
.next(sfn.Choice.jsonata(this, 'Match Title Template?')
// Look at the "title" field of issue in variables using Regex
.when(sfn.Condition.jsonata('{% $contains($issue.title, /(feat)|(fix)|(chore)\(\w*\):.*/) %}'), updateLabels, {
assign: {
type: '{% $match($states.input.title, /(\w*)\((.*)\)/).groups[0] %}',
component: '{% $match($states.input.title, /(\w*)\((.*)\)/).groups[1] %}',
}
})
.otherwise(notMatchTitleTemplate));
new sfn.StateMachine(this, 'StateMachine', {
definitionBody: sfn.DefinitionBody.fromChainable(definition),
timeout: Duration.minutes(5),
comment: 'automate issue labeling state machine',
});
python
import aws_cdk.aws_events as events
# connection: events.Connection
get_issue = tasks.HttpInvoke.jsonata(self, "Get Issue",
connection=connection,
api_root="{% 'https://' & $states.input.hostname %}",
api_endpoint=sfn.TaskInput.from_text("{% 'issues/' & $states.input.issue.id %}"),
method=sfn.TaskInput.from_text("GET"),
# Parse the API call result to object and set to the variables
assign={
"hostname": "{% $states.input.hostname %}",
"issue": "{% $parse($states.result.ResponseBody) %}"
}
)
update_labels = tasks.HttpInvoke.jsonata(self, "Update Issue Labels",
connection=connection,
api_root="{% 'https://' & $states.input.hostname %}",
api_endpoint=sfn.TaskInput.from_text("{% 'issues/' & $states.input.issue.id & 'labels' %}"),
method=sfn.TaskInput.from_text("POST"),
body=sfn.TaskInput.from_object({
"labels": "{% [$type, $component] %}"
})
)
not_match_title_template = sfn.Pass.jsonata(self, "Not Match Title Template")
definition = get_issue.next(sfn.Choice.jsonata(self, "Match Title Template?").when(sfn.Condition.jsonata("{% $contains($issue.title, /(feat)|(fix)|(chore)(w*):.*/) %}"), update_labels,
assign={
"type": "{% $match($states.input.title, /(w*)((.*))/).groups[0] %}",
"component": "{% $match($states.input.title, /(w*)((.*))/).groups[1] %}"
}
).otherwise(not_match_title_template))
sfn.StateMachine(self, "StateMachine",
definition_body=sfn.DefinitionBody.from_chainable(definition),
timeout=Duration.minutes(5),
comment="automate issue labeling state machine"
)
java
import software.amazon.awscdk.services.events.*;
Connection connection;
HttpInvoke getIssue = HttpInvoke.jsonata(this, "Get Issue", HttpInvokeJsonataProps.builder()
.connection(connection)
.apiRoot("{% 'https://' & $states.input.hostname %}")
.apiEndpoint(TaskInput.fromText("{% 'issues/' & $states.input.issue.id %}"))
.method(TaskInput.fromText("GET"))
// Parse the API call result to object and set to the variables
.assign(Map.of(
"hostname", "{% $states.input.hostname %}",
"issue", "{% $parse($states.result.ResponseBody) %}"))
.build());
HttpInvoke updateLabels = HttpInvoke.jsonata(this, "Update Issue Labels", HttpInvokeJsonataProps.builder()
.connection(connection)
.apiRoot("{% 'https://' & $states.input.hostname %}")
.apiEndpoint(TaskInput.fromText("{% 'issues/' & $states.input.issue.id & 'labels' %}"))
.method(TaskInput.fromText("POST"))
.body(TaskInput.fromObject(Map.of(
"labels", "{% [$type, $component] %}")))
.build());
Pass notMatchTitleTemplate = Pass.jsonata(this, "Not Match Title Template");
Chain definition = getIssue.next(Choice.jsonata(this, "Match Title Template?").when(Condition.jsonata("{% $contains($issue.title, /(feat)|(fix)|(chore)(w*):.*/) %}"), updateLabels, ChoiceTransitionOptions.builder()
.assign(Map.of(
"type", "{% $match($states.input.title, /(w*)((.*))/).groups[0] %}",
"component", "{% $match($states.input.title, /(w*)((.*))/).groups[1] %}"))
.build()).otherwise(notMatchTitleTemplate));
StateMachine.Builder.create(this, "StateMachine")
.definitionBody(DefinitionBody.fromChainable(definition))
.timeout(Duration.minutes(5))
.comment("automate issue labeling state machine")
.build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
using Amazon.CDK.AWS.Events;
Connection connection;
var getIssue = HttpInvoke.Jsonata(this, "Get Issue", new HttpInvokeJsonataProps {
Connection = connection,
ApiRoot = "{% 'https://' & $states.input.hostname %}",
ApiEndpoint = TaskInput.FromText("{% 'issues/' & $states.input.issue.id %}"),
Method = TaskInput.FromText("GET"),
// Parse the API call result to object and set to the variables
Assign = new Dictionary<string, object> {
{ "hostname", "{% $states.input.hostname %}" },
{ "issue", "{% $parse($states.result.ResponseBody) %}" }
}
});
var updateLabels = HttpInvoke.Jsonata(this, "Update Issue Labels", new HttpInvokeJsonataProps {
Connection = connection,
ApiRoot = "{% 'https://' & $states.input.hostname %}",
ApiEndpoint = TaskInput.FromText("{% 'issues/' & $states.input.issue.id & 'labels' %}"),
Method = TaskInput.FromText("POST"),
Body = TaskInput.FromObject(new Dictionary<string, object> {
{ "labels", "{% [$type, $component] %}" }
})
});
var notMatchTitleTemplate = Pass.Jsonata(this, "Not Match Title Template");
var definition = getIssue.Next(Choice.Jsonata(this, "Match Title Template?").When(Condition.Jsonata("{% $contains($issue.title, /(feat)|(fix)|(chore)(w*):.*/) %}"), updateLabels, new ChoiceTransitionOptions {
Assign = new Dictionary<string, object> {
{ "type", "{% $match($states.input.title, /(w*)((.*))/).groups[0] %}" },
{ "component", "{% $match($states.input.title, /(w*)((.*))/).groups[1] %}" }
}
}).Otherwise(notMatchTitleTemplate));
new StateMachine(this, "StateMachine", new StateMachineProps {
DefinitionBody = DefinitionBody.FromChainable(definition),
Timeout = Duration.Minutes(5),
Comment = "automate issue labeling state machine"
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
import events "github.com/aws/aws-cdk-go/awscdk"
var connection Connection
getIssue := tasks.HttpInvoke_Jsonata(this, jsii.String("Get Issue"), &HttpInvokeJsonataProps{
Connection: Connection,
ApiRoot: jsii.String("{% 'https://' & $states.input.hostname %}"),
ApiEndpoint: sfn.TaskInput_FromText(jsii.String("{% 'issues/' & $states.input.issue.id %}")),
Method: sfn.TaskInput_*FromText(jsii.String("GET")),
// Parse the API call result to object and set to the variables
Assign: map[string]interface{}{
"hostname": jsii.String("{% $states.input.hostname %}"),
"issue": jsii.String("{% $parse($states.result.ResponseBody) %}"),
},
})
updateLabels := tasks.HttpInvoke_Jsonata(this, jsii.String("Update Issue Labels"), &HttpInvokeJsonataProps{
Connection: Connection,
ApiRoot: jsii.String("{% 'https://' & $states.input.hostname %}"),
ApiEndpoint: sfn.TaskInput_*FromText(jsii.String("{% 'issues/' & $states.input.issue.id & 'labels' %}")),
Method: sfn.TaskInput_*FromText(jsii.String("POST")),
Body: sfn.TaskInput_FromObject(map[string]interface{}{
"labels": jsii.String("{% [$type, $component] %}"),
}),
})
notMatchTitleTemplate := sfn.Pass_Jsonata(this, jsii.String("Not Match Title Template"))
definition := getIssue.Next(sfn.Choice_Jsonata(this, jsii.String("Match Title Template?")).When(sfn.Condition_Jsonata(jsii.String("{% $contains($issue.title, /(feat)|(fix)|(chore)(w*):.*/) %}")), updateLabels, &ChoiceTransitionOptions{
Assign: map[string]interface{}{
"type": jsii.String("{% $match($states.input.title, /(w*)((.*))/).groups[0] %}"),
"component": jsii.String("{% $match($states.input.title, /(w*)((.*))/).groups[1] %}"),
},
}).Otherwise(notMatchTitleTemplate))
sfn.NewStateMachine(this, jsii.String("StateMachine"), &StateMachineProps{
DefinitionBody: sfn.DefinitionBody_FromChainable(definition),
Timeout: awscdk.Duration_Minutes(jsii.Number(5)),
Comment: jsii.String("automate issue labeling state machine"),
})
Properties
assignoptional{ [key: string]: any }assignoptionaltyping.Mapping[str, Any]assignoptionalMap<String, Object>AssignoptionalIDictionary<string, object>Assignoptional*map[string]interface{} #Workflow variables to store in this step.
Default: Not assign variables
Using workflow variables, you can store data in a step and retrieve that data in future steps.
commentoptionalstringcommentoptionalstrcommentoptionalStringCommentoptionalstringCommentoptional*string #An optional description for the choice transition.
Default: No comment
outputsoptionalanyoutputsoptionalAnyoutputsoptionalObjectOutputsoptionalobjectOutputsoptionalinterface{} #This option for JSONata only.
Default: $states.result or $states.errorOutput
notes
When you use JSONPath, then the state ignores this property. 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.