AWS Compute Blog
Prototyping at speed with AWS Step Functions new Workflow Studio
AWS recently introduced Workflow Studio for AWS Step Functions. This is a new visual builder for creating Step Functions workflows in the AWS Management Console. This post shows how to use the Workflow Studio for rapid workflow prototyping. It also explains how to transition to local development, integrating the prototype with your infrastructure as code templates.
Since its release in December 2016, developers have been building Step Functions workflows with Amazon States Language (ASL) to orchestrate multiple services into business-critical applications. Developers wanted faster ways to prototype and build orchestration workflows without writing custom code or using additional services.
What’s new?
The new Step Functions Workflow Studio provides an additional workflow building experience. Developers and business users can now build prototype workflows quickly with a graphical user interface in the Step Functions console.
These workflows can include all the same workflow states, patterns, and service integrations available when building with ASL. Each state is configured using editable forms. The workflow ASL definition can be exported for further editing in the console or in your local integrated development environment (IDE). Workflow Studio can build new workflows or edit a pre-existing workflow. To get started with Workflow Studio, see this introduction video.
Business users
Workflow Studio provides new opportunities for a more diverse range of users to build step functions workflows. Business users and those in non-technical roles can quickly create workflow prototypes. This can help to reason about and understand business processes before passing to a developer to add business logic and configure service integrations.
Rapid workflow prototyping
Workflow Studio allows you to create placeholders for AWS Lambda functions and other service integrations using the ‘drag-and-drop’ interface. This means that resources do not need to exist before designing the workflow. Once a workflow is prototyped you can save and continue to edit in the console or copy the ASL definition to your local IDE. You can then incorporate the workflow with application resources and infrastructure as code templates.
In the following steps, I use Workflow Studio to build the workflow described in this post. The full application template is found in this GitHub repository. The workflow analyzes web form submissions for negative sentiment. It generates a case reference number and saves the data in an Amazon DynamoDB table. The workflow returns the case reference number and message sentiment score.
To start fast prototyping for this workflow with the visual studio:
- Log into the Step Functions console and choose Create state machine.
- Choose Design your workflow visually from the authoring method section. This opens up Workflow Studio.
- Choose AWS Lambda Invoke from the Actions menu and drag it into the workflow.
- Choose the Configuration tab from the Form panel and enter the name Detect Sentiment in the State name field.
- In the function name field, choose Enter Function Name.
- Enter ${DetectSentiment} into the function name parameters field. This is a dynamic reference to a value that is provided by an Infrastructure-as-code template.
The Workflow Studio provides an interface to add input and output path processing configurations to the workflow. - Choose the Output tab and select Combine input and result with ResultPath. Selecting this option uses the ResultPath filter to add the result into the original state input. The specified path indicates where to add the result.
- Enter $.SentimentResults into the path ResultsPath text input.
- View the workflow ASL definition by choosing Definition from the top menu. This shows:
- The state is named Detect Sentiment.
- The Lambda function name uses a dynamic reference to ${DetectSentiment}. This is provided by the infrastructure-as-code template, explained in the following steps.
- A default retry configuration is defined.
- The ResultPath is configured.
Continue building the workflow this way, adding more Task and Flow states. A completed workflow looks as follows:
Transitioning to local development
Once the workflow is created in the Workflow Studio, you can export the ASL definition to a local IDE to incorporate into an infrastructure as code template. The template describes all the AWS resources that make up the application:
- To copy the ASL definition, choose the Definition button in the top navigation, and copy the entire ASL workflow definition to the clipboard.
- Create a new directory in your local filesystem named statemachine and save the definition to a file in this directory named sfn-template.asl.json. The following screenshot shows how the workflow appears in your IDE when rendered with the AWS Toolkit for Visual Studio Code.
AWS Serverless Application Model (AWS SAM) is an open-source infrastructure as code framework for building serverless applications.- Create an AWS SAM template named template.yaml to describe the application resources. A completed version of this file is found in this GitHub repository.
- Create a directory for each Lambda function. Within each directory, save the function code to a file called app.js. The function code, can be found in this GitHub repository. The final application file directory looks as follows:
root
┣ LambdaFunctions/
┃ ┣ GenerateReferenceNumber/
┃ ┃ ┗ app.js
┃ ┣ detectSentiment/
┃ ┃ ┗ app.js
┃ ┗ sendEmailConfirmation/
┃ ┗ app.js
┣ statemachine/
┃ ┗ sfn-template.asl.json
┗ template.yaml
The full application can be found in this GitHub repository.
The AWS SAM template describes the Step Functions workflow’s security permissions and allows for dynamic referencing of the resources described within the template such as the Lambda functions and DynamoDB table:
##########################################################################
# STEP FUNCTION #
##########################################################################
ProcessFormStateMachineExpressSync:
Type: AWS::Serverless::StateMachine # More info about State Machine Resource: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-statemachine.html
Properties:
DefinitionUri: statemachine/sfn-template.asl.json
DefinitionSubstitutions:
NotifyAdminWithSES: !Ref NotifyAdminWithSES
GenerateRefernceNumber: !Ref GenerateRefernceNumber
DetectSentiment: !Ref DetectSentiment
DDBTable: !Ref FormDataTable
Policies: # Find out more about SAM policy templates: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-policy-templates.html
- LambdaInvokePolicy:
FunctionName: !Ref NotifyAdminWithSES
- LambdaInvokePolicy:
FunctionName: !Ref DetectSentiment
- LambdaInvokePolicy:
FunctionName: !Ref GenerateRefernceNumber
- DynamoDBWritePolicy:
TableName: !Ref FormDataTable
Type: EXPRESS
- The DefinitionURI value provides the location of the ASL definition that is exported from the Workflow Studio, in statemachine/sfn-template.asl.json.
- The DefinitionSubstitutions values provide the names of the resources used within the workflow. Here you see $.DetectSentiment Lambda function name passed to the workflow definition. This was entered into the Workflow Studio in the previous steps.
The application is deployed using the AWS SAM CLI. Follow these steps in the GitHub repository to deploy the application.
Once the application is deployed, the workflow can be edited by updating the ASL definition in the Step Functions console or the local template file. It can also be edited from the drag-and-snap interface in the Workflow Studio. Any edits made in the AWS Management Console should be copied back to the local template file.
Conclusion
The AWS Step Functions Workflow Studio is a new visual builder for creating Step Functions workflows in the AWS Management Console. The drag-and-drop interface can be used to build new or edit existing workflows quickly. Each state is configured using editable forms, with the ASL definition visible and available for export as you build.
This post shows how to use the Workflow Studio for rapid workflow prototyping. It explains how to export the ASL definition to your local IDE and integrate it with your infrastructure as code application templates.
The Workflow Studio is included in Step Functions pricing at no additional fee and is available in all regions where Step Functions is available. To get started, visit https://aws.amazon.com/stepfunctions.