Tutorial 6: Save the workflow and execute the state machine - Amazon Step Functions
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Tutorial 6: Save the workflow and execute the state machine

Now that you’ve configured the resources of all the Amazon Web Services you’re using in the workflow prototype, you can save it as a Step Functions state machine and start executing it.

Step 1: Review the auto-generated state machine definition and save the state machine

As you drag and drop states from the Flow tab onto the canvas in Workflow Studio to build the workflow prototype, Step Functions automatically composes the Amazon States Language (ASL) definition of your workflow in real-time. You can edit this definition as required in the Code editor.

To review the ASL definition and save the state machine
  1. (Optional) Choose Definition on the Inspector to view the state machine's Amazon States Language (ASL) definition, which is automatically generated based on your selections in the Actions and Flow tabs and Inspector panel.


    To edit the definition, you can open the code editor by choosing Code on top of the page. For this tutorial, continue with the auto-generated definition.

  2. Specify a name for your state machine. To do this, choose the edit icon next to the default state machine name of MyStateMachine. Then, in State machine configuration, specify a name in the State machine name box.

    For this tutorial, enter the name CreditCardWorkflow.

  3. (Optional) In State machine configuration, specify other workflow settings, such as state machine type and its execution role.

    For this tutorial, keep all the default selections in State machine settings.


    (Optional) Step Functions automatically creates an execution role for the state machine with the least privileges required to invoke the RandomNumberforCredit Lambda function and publish to the Amazon SNS topic.

    If you've previously created an IAM role with the correct permissions for your state machine and want to use it, in Permissions, select Choose an existing role, and then select a role from the list. Or select Enter a role ARN and then provide an ARN for that IAM role.

  4. In the Confirm role creation dialog box, choose Confirm to continue.

    You can also choose View role settings to go back to State machine configuration.


    If you delete the IAM role that Step Functions creates, Step Functions can't recreate it later. Similarly, if you modify the role (for example, by removing Step Functions from the principals in the IAM policy), Step Functions can't restore its original settings later.

Step 2: Add the remaining IAM policies

Because Step Functions doesn't auto-generate the permissions to invoke the Lambda functions used in the Parallel state, you need to add the necessary policy.

To add the remaining policy
  1. On the CreditCardWorkflow page, choose the IAM role for your state machine to navigate to the IAM console. You’ll add the necessary permissions for the remaining Lambda functions on this page.

  2. Choose Add permissions, and then choose Attach policies.

  3. In the search box, type AWSLambdaRole and then press Enter.

  4. Choose AWSLambdaRole and then choose Attach policies. This policy is now added to the execution role of your state machine. This policy lets you invoke any Lambda function in your state machine.

Step 3: Run the state machine

State machine executions are instances where you run your workflow to perform tasks.

To execute the state machine
  1. On the CreditCardWorkflow page, choose Start execution.

    The Start execution dialog box is displayed.

  2. In the Start execution dialog box, do the following:

    1. (Optional) To identify your execution, you can specify a name for it in the Name box. By default, Step Functions automatically generates a unique execution name.


      Step Functions allows you to create names for state machines, executions, activities, and labels that contain non-ASCII characters. These non-ASCII names don't work with Amazon CloudWatch. To ensure that you can track CloudWatch metrics, choose a name that uses only ASCII characters.


      You don’t need to provide any input to execute this state machine. But you can specify an execution input, if required, in the Input area of the Start execution dialog box for other state machines. For an example of how to provide execution input to a state machine, see Step 4: Start a new execution of the Learn to use the Amazon Step Functions Workflow Studio tutorial.

    2. Choose Start execution.

  3. The Step Functions console directs you to a page that's titled with your execution ID. This page is known as the Execution Details page. On this page, you can review the execution results as the execution progresses or after it's complete.

    To review the execution results, choose individual states on the Graph view, and then choose the individual tabs on the Step details pane to view each state's details including input, output, and definition respectively. For details about the execution information you can view on the Execution Details page, see Execution Details page – Interface overview.