After this section, you will have a workflow that runs if there is capacity available.
In this section, you use an AWS SDK integration in Step Functions to query the service.
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. Copy the ARN value to a scratchpad - you will need this value later. 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 listexecutions
in the search bar. Drag the AWS Step Functions ListExecutions action from the list to between the Shop Open? and Pass states in the designer.
ListExecutions
.YOUR_STATE_MACHINE_ARN
with the ARN you copied earlier.{
"StateMachineArn": "YOUR_STATE_MACHINE_ARN",
"MaxResults": 100,
"StatusFilter": "RUNNING"
}
Check you Replaced YOUR_STATE_MACHINE_ARN with the correct ARN.
$.isCapacityAvailable
in the value textbox.The workflow must branch logic depending on the value returned by the ListExecutions SDK call. In this section, you add the branching logic.
$.isCapacityAvailable.Executions[20]
.Double-check that the NOT dropdown is blank before continuing
Is capacity available?
.{
"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": "ListExecutions"
},
"ListExecutions": {
"Type": "Task",
"Next": "Is capacity available?",
"Parameters": {
"StateMachineArn": "YOUR_STATE_MACHINE_ARN",
"MaxResults": 100,
"StatusFilter": "RUNNING"
},
"Resource": "arn:aws:states:::aws-sdk:sfn:listExecutions",
"ResultPath": "$.isCapacityAvailable"
},
"Is capacity available?": {
"Type": "Choice",
"Choices": [
{
"Variable": "$.isCapacityAvailable.Executions[20]",
"IsPresent": 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
}
}
}
Choose Apply and exit.
In the Edit OrderProcessorWorkflow page, choose Save.
In this section, you will test the changes to the 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 Is capacity available? status to show the details on the right side.
Next, you’ll add a human-readable order number to each execution.