Front-End Web & Mobile
Integrate AWS Step Functions with AWS Amplify using Amplify Custom Resources
AWS Amplify makes it possible to add custom AWS resources to an Amplify-created backend using the amplify add custom
command and the AWS Cloud Development Kit (AWS CDK) or AWS CloudFormation. By doing so, developers can easily add and manage AWS resources beyond Amplify’s built-in use cases to their projects.
AWS Amplify makes it fast and easy to build cloud-powered mobile and web apps on AWS. Amplify comprises a set of tools and services that enable frontend web and mobile developers to leverage the power of AWS services to build innovative and feature-rich applications. The Amplify CLI is a command line toolchain that helps frontend developers create app backends in the cloud.
In this blog post, we’ll use an Amplify custom resource to add an AWS Step Functions workflow to our Amplify project.
AWS Step Functions is a serverless orchestration service that lets you combine AWS Lambda functions and more than 10,000 AWS API actions to build business-critical applications. Step Functions workflows manage failures, retries, parallelization, service integrations, and observability so developers can focus on higher-value business logic.
What we’ll learn
- How to create a Step Functions workflow as an Amplify custom resource using the AWS CDK.
- How to connect our custom resource to an existing Amplify-managed GraphQL API.
What we’ll build

Figure 1. Architecture diagram: what we’re going to build.
The proposed solution consists of the following elements:
- Our sample web application is a customer feedback form built using Vite and Amplify UI.
- Submitting the feedback form will trigger a Step Functions express workflow created as an Amplify custom resource via an AWS AppSync API managed by Amplify.
- The Step Function workflow will detect the sentiment of the submitted feedback using Amazon Comprehend’s
DetectSentiment
API. - Next, the workflow will store the feedback and detected sentiment in an Amplify-managed Amazon DynamoDB table.
- If a non-positive sentiment is detected, the workflow will trigger a notification to a customer support email address using the Amazon Simple Notification Service (Amazon SNS).
- Depending on the result of the sentiment analysis, our web application will display different confirmation messages to the customer.
The Step Functions workflow looks like this:

Figure 2. Step Functions workflow for processing user feedback.
From the perspective of the user of our web application, the result will look like this:

Figure 3. Demonstration of the outcome of this solution.
Walkthrough
Prerequisites
- An AWS Account.
- Node.js and git installed.
Setting up the Amplify CLI
To install the Amplify CLI, use the following command:
Setting up the base Amplify project
Next, clone the sample project from the aws-samples
GitHub repository:
Next, we are going to use the Amplify CLI to create the resources contained in the sample project in our AWS account with the following command:
Set up the project as depicted in the following screenshot:
Amplify will now set up our project environment in AWS and notify us once it’s done:
We are now ready to add AWS resources to our Amplify stack using the Amplify CLI.
Setting up a GraphQL API
We will start by adding a GraphQL API to our Amplify stack. Later in the walkthrough, we will connect our Step Functions workflow here.
Execute the following command and configure the API as depicted below:
Open the schema.graphql
file located in amplify/backend/api/<project_name>/
. Define the following GraphQL schema:
"""
Creates a database table for 'Feedback' to store the feedbacks
submitted through our web application.
"""
type Feedback @model @auth(rules: [{ allow: public }]) {
id: ID!
content: String!
sentiment: String
}
"""
Create a new 'Execution' type that will be returned by our call
to the Step Functions workflow.
"""
type Execution {
name: String
status: String
input: String
executionArn: String
startDate: String
stopDate: String
output: String
}
"""
Mutation that triggers the synchronous execution of our Step
Functions workflow.
"""
type Mutation {
executeStateMachine(input: String!): Execution @aws_api_key
}
Have Amplify apply this schema to our resources in AWS by running the following command:
When asked if you want Amplify to generate code for the newly created GraphQL API, answer “Yes”, specify “javascript” as target language, and confirm the other default options:
Adding an Amplify custom resource
To add a Step Functions workflow to our Amplify project, we’re going to use an Amplify custom resource:
After we specify a name for our Amplify custom resource, Amplify will create an empty AWS CDK stack for us in the directory amplify/backend/custom/<our custom resource name>/
.
Importing the required dependencies to our AWS CDK stack
We can now customize the stack’s code to add our Step Functions resource and connect it to our GraphQL API. You can find the complete example code for the custom resource stack in the template/
directory in the cloned git repository or here on GitHub. We will discuss the code step by step in this walkthrough.
We add AWS resources to our AWS CDK stack by first opening amplify/backend/custom/<name of custom resource>/cdk-stack.ts
.
Let’s add the dependencies we’re going to need to build our Step Functions workflow and remove the commented-out AWS CDK resources so that our file matches the following.
Replace the content of cdk-stack.ts
with:
Referencing our existing GraphQL API in the custom resource stack
As a first step, we will reference our existing GraphQL API resource as a dependency in the AWS CDK stack. You can find the name of the API resource by looking at the name of the directory generated by the Amplify CLI. Note that the name of this folder might be different if you have named the project differently:
Update the name of the API resource in two places if it is not amplifysfn
as in our example:
Creating a Step Functions workflow in the custom resource stack
Now we can create our Step Function workflow directly inside the AWS CDK stack using the @aws-cdk/aws-stepfunctions
and @aws-cdk/aws-stepfunctions-tasks
modules. We’ll start by creating the state machine definition which contains all its tasks and logic states:
We have now received a result from the DetectSentiment
API and stored it in DynamoDB together with the original input. Next, our Step Function should handle positive and non-positive results differently.
Defining the Step Functions resource
Finally, based on our state machine definition we can define the Step Functions workflow resource. Additionally, we need to define the correct IAM access rights for our workflow to execute the contained tasks.
Integrating the workflow with the GraphQL API
Now that the Step Functions workflow is design our AWS CDK stack, we can create a new resolver for our GraphQL API data source that references the workflow’s Amazon Resource Name (ARN):
As you can see, the resolver references both a request mapping template and a response mapping template. These mapping templates define how our GraphQL resolver communicates with a data source – in this case the Step Functions workflow. Let’s define both a request and a response mapping template in cdk-stack.ts
:
Again, to get a full view of the code for our custom Amplify stack, make sure to take a look at the file in GitHub.
Deploying the Amplify custom resource
Move back to the project root and deploy your the custom resource to AWS:
You will receive an email asking you to confirm your subscription to the customer support SNS topic. Your confirmation is necessary to make sure the workflow executes successfully.
Testing the workflow
Now that we have our Amplify resources set up, let’s also prepare the sample web application. The sample code you cloned from GitHub contains a skeleton web application scaffolded using Vite. Back in the project root directory, install the project’s required dependencies using npm:
To test our workflow, start the web application via:
Let’s try entering a positive and then a negative feedback in the form. As demonstrated in Figure 3, you will see different success messages depending on the sentiment of your feedback after you hit the Submit button. In addition, feedback that does not have a positive sentiment will trigger an email being sent via the customer support SNS topic.
Cleaning up
To remove the resources created as part of this walkthrough, run amplify delete
from the project root directory and follow the instructions in the CLI.
Conclusion
In this blog post, you’ve learned how to set up a Step Functions workflow as an Amplify custom resource and how to connect it to an Amplify-managed GraphQL API. Consult the Amplify custom resource documentation to learn more about integrating AWS services into your Amplify projects. Learn more about AWS Step Functions in the AWS Step Functions Workshop and extend the sample workflow using the AWS CDK documentation for AWS Step Functions.
Share your feedback by opening a GitHub issue or via the comments below.