This sample project demonstrates how to use an AWS Step Functions Express Workflow to process messages or data from a high-volume event source, such as Amazon Simple Queue Service (Amazon SQS). Because Express Workflows can be started at a very high rate, they are ideal for high-volume event processing or streaming data workloads.
Here are two commonly used methods to execute your state machine from an event source:
-
Configure an Amazon CloudWatch Events rule to start a state machine execution whenever the event source emits an event. For more information, see Creating a CloudWatch Events Rule That Triggers on an Event.
-
Map the event source to a Lambda function, and write function code to execute your state machine. The AWS Lambda function is invoked each time your event source emits an event, in turn starting a state machine execution. For more information see Using AWS Lambda with Amazon SQS.
This sample project uses the second method to start an execution each time the Amazon SQS queue sends a message. You can use a similar configuration to trigger Express Workflows execution from other event sources, such as Amazon Simple Storage Service (Amazon S3), Amazon DynamoDB, and Amazon Kinesis.
For more information about Express Workflows and Step Functions service integrations, see the following:
Step 1: Create the state machine
-
Open the Step Functions console
and choose Create state machine. -
Choose Create from template and find the related starter template. Choose Next to continue.
-
Choose how to use the template:
-
Run a demo – creates a read-only state machine. After review, you can create the workflow and all related resources.
-
Build on it – provides an editable workflow definition that you can review, customize, and deploy with your own resources. (Related resources, such as functions or queues, will not be created automatically.)
-
-
Choose Use template to continue with your selection.
Note
Standard charges apply for services deployed to your account.
Step 2: Trigger the state machine execution
-
Open the Amazon SQS console
. -
Select the queue that was created by the sample project.
The name will be similar to Example-SQSQueue-wJalrXUtnFEMI.
-
In the Queue Actions list, select Send a Message.
-
Use the copy button to copy the following message, and on the Send a Message window, enter it, and choose Send Message.
Note
In this sample message, the
input:
line has been formatted with line breaks to fit the page. Use the copy button or otherwise ensure that it is entered as a single line with no breaks.{ "input": "QW5kIGxpa2UgdGhlIGJhc2VsZXNzIGZhYnJpYyBvZiB0aGlzIHZpc2lvbiwgVGhlIGNsb3VkLWNhcHBlZCB0b3dlcnMsIHRoZSBnb3JnZW
-
Choose Close.
-
Open the Step Functions console.
-
Go to your Amazon CloudWatch Logs log group
and inspect the logs. The name of the log group will look like example-ExpressLogGroup-wJalrXUtnFEMI.