Working with AWS Step Functions - AWS Toolkit for VS Code

Working with AWS Step Functions

You can use the AWS Toolkit for Visual Studio Code (VS Code) to perform various operations with state machines.

Prerequisites

  • Be sure your system meets the prerequisites specified in Installing the Toolkit for VS Code, then install the toolkit.

  • Ensure that you have configured your credentials before opening the AWS Explorer.

Work with state machines in VS Code

You can use VS Code to interact with remote state machines, and develop state machines locally in JSON or YAML format. You can create or update state machines, list existing state machines, run them, and download them. VS Code also lets you create new state machines from templates, see a visualization of your state machine, and provides code snippets, code completion, and code validation.

List existing state machines

If you've already created state machines, you can view a list of them:

  1. Open the AWS Explorer.

  2. Select Step Functions

  3. Verify that it lists all the state machines in your account.

Download a state machine

To download a state machine:

  1. In the AWS Explorer, right click the state machine that you want to download.

  2. Select Download, then select the location where you want to download the state machine.

  3. Verify that it downloaded correctly.

Create a state machine

You can create a new state machine yourself, or you can use a template. For more information on creating a state machine from a template, see the State Machine Templates section. To create a new state machine:

  1. Create a new Amazon States Language (ASL) file with your state machine definition. Use the menu at the bottom right to set it as Amazon States Language.

  2. Select Publish to Step Functions.

  3. Select Quick Create, choose a role, and name your state machine.

Update a state machine

To update a state machine:

  1. Edit the ASL file with your state machine definition.

  2. Select Publish to Step Functions.

  3. Select Quick Update, then select the state machine you want to update.

Run a state machine

To run a state machine:

  1. In the AWS Explorer, right click the state machine that you want to run.

  2. Provide input for the state machine. You can try both input from a file, and input in a text box.

  3. Start the state machine and verify that it runs successfully.

State machine templates

When you create a state machine, you have the option to create it from a template. The template contains a sample state machine definition with several commonly used states, and provides you with a starting point. To use state machine templates:

  1. Open the Command Palette in VS Code.

  2. Select AWS Toolkit Create a new Step Functions state machine.

  3. Choose the template you want to use.

  4. Choose whether you want to use the JSON or the YAML template format.

State machine graph visualization

Graph visualizations let you see what your state machine looks like in graphical format. When you create a graph visualization, another tab will open and display a visualizion of the state machine JSON or YAML. You can then compare the state machine definition you are writing concurrently with its visualization. As you change your state machine definition, the visualization will be updated.

Note

To create a visualizion of a state machine definition, the definition must be open in the active editor. If you close or rename the definition file, the visualization will close.

To create a state machine graph visualization:

  1. Define your state machine.

  2. Open the Command Palette in VS Code.

  3. To create a visualization, use the visualization button in the upper right corner, or choose AWS Render graph.

Code snippets

Code snippets let you insert short sections of code. To use code snippets:

  1. Open a file and save it with the extension .asl.json for JSON format, or .asl.yaml for YAML format.

  2. Create a new state machine with the States property.

  3. Place the cursor within States.

  4. Use the key combination Control + Space, and select your preferred code snippet.

  5. Use Tab to traverse the variable and parameters in the code snippet.

  6. Test Retry and Catch snippets by placing the cursor within the related state.

Code completion and validation

To see how code completion works:

  1. Create several states.

  2. Place the cursor after a Next, StartAt, or Default property.

  3. Use the key combination Control + Space to list available completions. Additional properties can be accessed using Control + Space again, and will be based on the Type of the State.

  4. As you work, code validation will happen for:

    • Missing properties

    • Incorrect values

    • No terminal state

    • Nonexistent states that are pointed to