Using AWS Application Composer with AWS Step Functions
AWS Application Composer features an integration with AWS Step Functions Workflow Studio. Use Application Composer to do the following:
-
Launch Step Functions Workflow Studio directly within Application Composer.
-
Create and manage new workflows or import existing workflows into Application Composer.
-
Integrate your workflows with other AWS resources using the Application Composer canvas.
![An image of a Step Functions State machine card.](/images/application-composer/latest/dg/images/aac_use_sf_01.png)
With Step Functions Workflow Studio in Application Composer, you can use the benefits of two powerful visual designers in a single place. As you design your workflow and application, Application Composer creates your infrastructure as code (IaC) to guide you towards deployment.
Topics
Getting started with Step Functions Workflow Studio in Application Composer
To get started, you can create new workflows or import existing workflows.
Create a new workflow
To create a new workflow
-
From the Resources palette, drag a Step Functions State machine enhanced component card onto the canvas.
When you drag a Step Functions State machine card onto the canvas, Application Composer creates the following:
-
An
AWS::Serverless::StateMachine
resource that defines your state machine. By default, Application Composer creates a standard workflow. To create an express workflow, change theType
value in your template fromSTANDARD
toEXPRESS
. -
An
AWS::Logs::LogGroup
resource that defines an Amazon CloudWatch log group for your state machine.
-
-
Open the card’s Resource properties panel and select Edit in Workflow Studio to open Workflow Studio within Application Composer.
Step Functions Workflow Studio opens in Design mode. To learn more, see Design mode in the AWS Step Functions Developer Guide.
Note
You can modify Application Composer to save your state machine definition in an external file. To learn more, see Working with external files.
-
Create your workflow and choose Save. To exit Workflow Studio, choose Return to Application Composer.
Application Composer defines your workflow using the
Defintion
property of theAWS::Serverless::StateMachine
resource. -
You can modify your workflow by doing any of the following:
-
Open Workflow Studio again and modify your workflow.
-
For Application Composer from the console, you can open the Template view of your application and modify your template. If using local sync, you can modify your workflow in your local IDE. Application Composer will detect your changes and update your workflow in Application Composer.
-
For Application Composer from the Toolkit for VS Code, you can directly modify your template. Application Composer will detect your changes and update your workflow in Application Composer.
-
Import existing workflows
You can import workflows from applications that are defined using AWS Serverless Application Model (AWS SAM) templates. Any state machine defined using the AWS::Serverless::StateMachine
resource type will visualize as a Step Functions State machine enhanced component card that you can use to launch Workflow Studio.
The AWS::Serverless::StateMachine
resource can define workflows using either of the following properties:
-
Definition
– The workflow is defined within the AWS SAM template as an object. -
DefinitionUri
– The workflow is defined on an external file using the Amazon States Language. The file’s local path is then specified with this property.
Definition property
- Application Composer from the console
-
For workflows defined using the
Definition
property, you can import a single template or the entire project.-
Template – For instructions on importing a template, see Import an existing project template. To save changes that you make within Application Composer, you must export your template.
-
Project – When you import a project, you must activate local sync. Changes that you make are automatically saved to your local machine. For instructions on importing a project, see Import an existing project folder.
-
- Application Composer from the Toolkit for VS Code
-
For workflows defined using the
Definition
property, you can open Application Composer from your template. For instructions, see Accessing Application Composer from the AWS Toolkit for Visual Studio Code.
DefinitionUri property
- Application Composer from the console
-
For workflows defined using the
DefinitionUri
property, you must import the project and activate local sync. For instructions on importing a project, see Import an existing project folder. - Application Composer from the Toolkit for VS Code
-
For workflows defined using the
DefinitionUri
property, you can open Application Composer from your template. For instructions, see Accessing Application Composer from the AWS Toolkit for Visual Studio Code.
Using Step Functions Workflow Studio in Application Composer
Build workflows
Application Composer uses definition substitutions to map workflow tasks to resources in your application. To learn more about
definition substitutions, see
DefinitionSubstitutions
in the AWS Serverless Application Model Developer Guide.
When you create tasks in Workflow Studio, specify a definition substitution for each task. You can then connect tasks to resources on the Application Composer canvas.
To specify a definition substitution in Workflow Studio
-
Open the Configuration tab of the task and locate the API Parameters field.
-
If the API Parameters field has a drop down option, choose Enter a AWS CloudFormation substitution. Then, provide a unique name.
For tasks that connect to the same resource, specify the same definition substitution for each task. To use an existing definition substitution, choose Select a AWS CloudFormation substitution and select the substitution to use.
-
If the API Parameters field contains a JSON object, modify the entry that specifies the resource name to use a definition substitution. In the following example, we change
"MyDynamoDBTable"
to"${RecordTransaction}"
. -
Select Save and Return to Application Composer.
The tasks from your workflow will visualize on the Step Functions State machine card.
![An image of a Step Functions State machine card with tasks visualized.](/images/application-composer/latest/dg/images/aac_use_sf_03.png)
Connect resources to workflow tasks
You can create connections in Application Composer between supported workflow tasks and supported Application Composer cards.
-
Supported workflow tasks – Tasks for AWS services that are optimized for Step Functions. To learn more, see Optimized integrations for Step Functions in the AWS Step Functions Developer Guide.
-
Supported Application Composer cards – Enhanced component cards are supported. To learn more about cards in Application Composer, see Configure Application Composer cards.
When creating a connection, the AWS service of the task and card must match. For example, you can connect a workflow task that invokes a Lambda function to a Lambda Function enhanced component card.
To create a connection, click and drag the port of a task to the left port of an enhanced component card.
![An image of a Step Functions State machine card with a task connected to a Lambda function resource card.](/images/application-composer/latest/dg/images/aac_use_sf_04.png)
Application Composer will automatically update your DefinitionSubstitution
value to define your connection. The
following is an example:
Transform: AWS::Serverless-2016-10-31 Resources: StateMachine: Type: AWS::Serverless::StateMachine Properties: Definition: StartAt: Check Stock Value States: Check Stock Value: Type: Task Resource: arn:aws:states:::lambda:invoke Parameters: Payload.$: $ FunctionName: ${CheckStockValue} Next: Choice ... DefinitionSubstitutions: CheckStockValue: !GetAtt CheckStockValue.Arn ... CheckStockValue: Type: AWS::Serverless::Function Properties: ...
IAM policies
When you connect tasks from your workflow to resources, Application Composer automatically creates the AWS Identity and Access Management (IAM) policies required to authorize the interaction between your resources. The following is an example:
Transform: AWS::Serverless-2016-10-31 Resources: StockTradingStateMachine: Type: AWS::Serverless::StateMachine Properties: ... Policies: - LambdaInvokePolicy: FunctionName: !Ref CheckStockValue ... CheckStockValue: Type: AWS::Serverless::Function ...
If necessary, you can add more IAM policies to your template.
Working with external files
When you create a workflow from the Step Functions State machine card, Application Composer saves your
state machine definition within your template using the Definition
property. You can configure
Application Composer to save your state machine definition on an external file.
Note
To use this feature with Application Composer from the AWS Management Console, you must have local sync activated. For more information, see Automatically sync and save your project.
To save your state machine definition on an external file
-
Open the Resource properties panel of your Step Functions State machine card.
-
Select the Use external file for state machine definition option.
-
Provide a relative path and name for your state machine definition file.
-
Choose Save.
Application Composer will do the following:
-
Move your state machine definition from the
Definition
field to your external file. -
Save your state machine definition in an external file using the Amazon States Language.
-
Modify your template to reference the external file using the
DefinitionUri
field.
Learn more
To learn more about Step Functions in Application Composer, see the following:
-
Using Workflow Studio in Application Composer in the AWS Step Functions Developer Guide.
-
DefinitionSubstitutions in AWS SAM templates in the AWS Step Functions Developer Guide.