# ChoiceTransitionOptions

Options for Choice Transition.

Extends: ChoiceTransitionOptions
Extends: AssignableStateOptions

- Source: [`aws-stepfunctions/lib/states/state.ts`](https://github.com/aws/aws-cdk/blob/v2.274.0/packages/aws-cdk-lib/aws-stepfunctions/lib/states/state.ts#L678)
- Type last changed: v2.178.0 · 6 Feb 2025

## 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',
});
```

## Properties

- `assign`: { [key: string]: any } — 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.

- `comment`: string — An optional description for the choice transition.

  **Default:** No comment

- `outputs`: any — This option for JSONata only.

  **Default:** $states.result or $states.errorOutput

  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.
