After this section, you will have a workflow that emits several new events.
In this section, you add an EventBridge PutEvents state that emits an event if either the customer or barista times out an order. You have already created the logic to handle time outs so only need to use EventBridge to emit an event.
Go to the Step Functions console. From the AWS Management Console, select Services then select Step Functions under Application Integration. Make sure your region is correct.
From the left-hand menu, select State machine and choose OrderProcessorWorkflow from the list. Choose Edit.
On the next page, choose Workflow Studio to open the workflow in the designer.
With the Actions tab selected on the left, enter putevents
in the search bar. Drag the Amazon EventBridge PutEvents action from the list to between the Customer timeout and End states in the designer.
Emit - error timeout
.{
"Entries": [
{
"Detail": {
"Message": "The order timed out. Step Functions waits a set amount of time (5 minutes for a customer, 15 minutes for a barista), no action was taken and so the order is ended.",
"userId.$": "$.detail.userId",
"orderId.$": "$.detail.orderId",
"cause.$": "$.cause"
},
"DetailType": "OrderProcessor.OrderTimeOut",
"EventBusName": "Serverlesspresso",
"Source": "awsserverlessda.serverlesspresso"
}
]
}
In this section, you add an EventBridge PutEvents state that emits a final event when the order has finished, and the workflow has completed.
putevents
in the search bar. Drag the Amazon EventBridge PutEvents action from the list to between the Pass and End states in the designer.{
"Entries": [
{
"Detail": {
"Message": "The order has reached the end of the workflow, and so a final event is emitted to alert other services to this.",
"userId.$": "$.detail.userId",
"orderId.$": "$.detail.orderId"
},
"DetailType": "OrderProcessor.orderFinished",
"EventBusName": "Serverlesspresso",
"Source": "awsserverlessda.serverlesspresso"
}
]
}
In this section, you update the EventBridge PutEvents state that was created earlier to emit an event if the shop is closed or there is no capacity to accept new orders.
{
"Entries": [
{
"Detail": {
"Message": "The Step functions workflow checks if the shop is open and has capacity to serve a new order by invoking a Lambda function that queries the Shop config service. The shop was not ready, and so a 'not ready' event is emitted to cancel the current order.",
"userId.$": "$.detail.userId"
},
"DetailType": "OrderProcessor.ShopUnavailable",
"EventBusName": "Serverlesspresso",
"Source": "awsserverlessda.serverlesspresso"
}
]
}
Choose Apply and exit. In the Edit page, choose Save.
In the IAM role popup, choose Save anyway.
Next, you’ll test the workflow to see how the execution path changes depending on the shop state and barista capacity.