Until now, you have manually started the
OrderProcessor workflow from the Step Functions console.
In production, the workflow is started by an event generated from the Validator service. The event is emitted each time a QR code is scanned by a customer.
- You will create a new rule in Amazon EventBridge that passes the Validator event to your OrderProcessor workflow.
- You will test the new rule by mocking the event sent from the Validator service.
Creating the “New Order” rule
In this section, you will build the rule that listens to the
Validator.NewOrder event and passes this to the order workflow target.
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:
- For the Name, enter NewOrder.
- For Event bus, enter
- Choose Next.
- In Step 2 of the wizard:
- For Event source, select Other.
- Ignore the Sample event panel.
- In the Event pattern panel, paste the following:
- Choose Next
- In Step 3 of the wizard:
- In the Target 1 panel, choose AWS service.
- In the Select a target dropdown, choose Step Functions state machine
- In the State machine dropdown, choose OrderProcessorWorkflow. Tip: You can start typing
OrderProcessor into the search box to find the workflow.
- For Execution role, ensure Create a new role for the specific resource is selected.
- Choose Next.
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.
Testing the “New Order” rule
In this section, you will test the rule that starts the OrderProcessor workflow when the NewOrder event is emitted.
From the AWS EventBridge Console, under Events:
- Choose Event buses.
- Choose the Serverlesspresso event bus
Choose Send events
Check that the serverlesspresso event bus is selected
Copy the following into the Event source input:
- Copy the following into the Detail type input:
- Copy the following into the Event detail input:
- Choose Send
This should create an event ID with a confirmation summary:
This starts a new execution in the
- From the AWS Step Functions console, select the OrderProcessorWorkflow you created earlier. You will see the most recent execution with the Status, Running.
- Choose the latest execution from the Name column. The console shows the Execution status of Running. The left side shows the flow of execution with the green states showing the actual path. The blue state shows when execution is suspended, pending a callback.
The new rule has successfully routed the
NewOrder event to the
OrderProcessor workflow. In the next step, you create a rule that routes the
WorkflowStarted event to an AWS Lambda function.
- Before this section, the Validator service published events to the custom bus when the QR code is scanned but nothing was subscribed to these events. You created a rule that subscribes to Validator events and routes the traffic to the order workflow.
- To test, instead of scanning a QR code to trigger the Validator service, you mocked an example event and published it to the custom event bus using the CLI.
- You verified that the Validator event triggered the rule and started the workflow.
Next, you’ll create an event that the Order Manager microservice uses to persist details of orders.