The Order Processor workflow built in module emits the WorkflowStarted
event. At this point in the order, the workflow has checked that the shop is open and that the barista has capacity for the new order. The workflow now waits for up to 15 minutes for the customer to choose and submit their coffee order. This is the first time in the process that the order waits for human interaction.
Step Functions does this by implementing the Wait for callback Task Token pattern. It passes the task token to the integrated service (Amazon EventBridge). The task pauses until the workflow receives that task token back with a SendTaskSuccess
or SendTaskFailure
call.
In the next step you create the rule that receives the WorkflowStarted
event containing the task token. You route this event to an AWS Lambda Function which persists the token to an AWS DynamoDB table, along with the unique order ID.
The Order Manager service keeps track of all the individual drink orders (e.g. “Double espresso”) and their completion status. The service is used by the Barista and Customer Apps to fetch lists of open or completed orders. This service is kept in sync by listening to events from the workflow.
In this section:
Go to the EventBridge console. From the AWS Management Console, select Services then select EventBridge Application Integration. Make sure your region is correct.
Choose Rules. Choose Create rule.
In Step 1 of the wizard:
Serverlesspresso
.{
"detail-type": ["OrderProcessor.WorkflowStarted"],
"source": ["awsserverlessda.serverlesspresso"]
}
WorkflowStarted
from the Function dropdown. This was deployed by the core stack in the setup module. Tip: you can start typing “WorkflowStarted” into the field to find the function.In Step 4 of the wizard, choose Next.
In Step 5 of the wizard, check that the Define rule detail panel that the Event bus is Serverlesspresso
. Choose Create rule.
In this section, you will test that the rule invokes the WorkflowStarted Lambda function, and inspect the event payload and results.
To start a new workflow, from the AWS EventBridge Console, under Events:
Choose Event busses.
Choose the Serverlesspresso event bus
Choose Send events
Check that the serverlesspresso event bus is selected
Copy the following into the Event source input:
awsserverlessda.serverlesspresso
Validator.NewOrder
{"userId":"1","orderId":"1"}
The rule you created called NewOrder triggers the OrderProcessor
workflow. This in turn sends a WorkflowStarted
event to the Serverlesspresso event bus.
Go to the CloudWatch console. From the AWS Management Console, select Services then select CloudWatch in Management & Governance. Make sure your region is correct.
From the left menu, choose Log groups. Choose the log group called /aws/events/serverlesspressoEventBus
.
OrderProcessor.WorkflowStarted
event that was processed by the event bus.This shows all the event information, including the TaskToken
generated by Step Functions, the event detail-type
, and the event’s source
.
The new WorkflowStarted rule has routed this event to the WorkflowStarted Lambda function. This Lambda function writes the task token to a DynamoDB table named serverlesspresso-order-table.
Go to the DynamoDB console. From the AWS Management Console, select Services then select DynamoDB in Database. Make sure your region is correct.
Select Explore items in the Tables menu on the left. Select the table serverlesspresso-order-table
.
TaskToken
, the Order ID (“SK”), and the “ORDERSTATE”:When the customer submits the drink order from the Customer App, the Order Manager microservice will fetch this task token from DynamoDB and return it to the Step Functions service. This is then used to resume the workflow for that order.
In the next section you will see how orders are canceled, updated, and completed by a separate workflow called the OrderManager
Congratulations! You have configured rules to process events and deliver selected events to different targets. This connects backend microservices together when events occur throughout the workload. In the next section, you will use the three frontend applications to test the backend.