After this section, you will have a workflow that runs based if the shop is open.
First, remove the pass state from the workflow that you added in the previous section.
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.
Delete the pass state added in the previous section. Click the state in the designer window and then choose Delete in the toolbar.
In this section, you use a direct service integration in Step Functions to query an item from a DynamoDB table.
DynamoDB Get Shop status
.{
"TableName": "serverlesspresso-config-table",
"Key": {
"PK": {
"S": "config"
}
}
}
$.GetStore
in the value textbox.The workflow must branch logic depending on the value read from the DynamoDB table. In this section, you add the branching logic.
GetItem
state.$.GetStore.Item.storeOpen.BOOL
. This JSONPath syntax specifies the storeOpen Boolean attribute from the DynamoDB query response.Shop Open?
.{
"Comment": "A description of my state machine",
"StartAt": "DynamoDB Get Shop Status",
"States": {
"DynamoDB Get Shop Status": {
"Type": "Task",
"Resource": "arn:aws:states:::dynamodb:getItem",
"Parameters": {
"TableName": "serverlesspresso-config-table",
"Key": {
"PK": {
"S": "config"
}
}
},
"ResultPath": "$.GetStore",
"Next": "Shop Open?"
},
"Shop Open?": {
"Type": "Choice",
"Choices": [
{
"Not": {
"Variable": "$.GetStore.Item.storeOpen.BOOL",
"BooleanEquals": true
},
"Next": "PutEvents"
}
],
"Default": "Pass"
},
"PutEvents": {
"Type": "Task",
"End": true,
"Parameters": {
"Entries": [
{}
]
},
"Resource": "arn:aws:states:::aws-sdk:eventbridge:putEvents"
},
"Pass": {
"Type": "Pass",
"End": true
}
}
}
In the Edit OrderProcessorWorkflow page, choose Save.
In the IAM role popup, choose Save anyway. The IAM role you are using was deployed in the setup module and has the necessary permissions.
In this section, you will test the new workflow.
From the previous section, on the page showing the new workflow, choose Start execution. In the Start execution pop-up, choose Start execution.
After the execution is finished, the console shows a results page. The left side shows the flow of execution with the green states showing the actual path. Choose the Shop Open? status to show the details on the right side.
storeOpen
attribute is TRUE, causing the choice state to choose the Pass state.Next, you’ll check store capacity before allowing the order to continue.