The name check and the address check do not depend on each other, so they can run at the same time. A Parallel state runs several branches, waits for all of them and returns an array with the output of each branch, in order.
ResultPath is $.checks, so checks[0] is the name result and checks[1] the address result.$.checks[0].flagged and $.checks[1].flagged.Catch for UnprocessableDataException moves to the Parallel state: an error in any branch stops the whole Parallel state.cd ~/workshop-dir
cat > statemachine/account-application-workflow.asl.json <<'EOF'
{
"StartAt": "Check Applicant Data",
"States": {
"Check Applicant Data": {
"Type": "Parallel",
"Branches": [
{
"StartAt": "Check Name",
"States": {
"Check Name": {
"Type": "Task",
"Parameters": {
"command": "CHECK_NAME",
"data": {
"name.$": "$.application.name"
}
},
"Resource": "${DataCheckingFunctionArn}",
"Retry": [
{
"ErrorEquals": [
"Lambda.ServiceException",
"Lambda.AWSLambdaException",
"Lambda.SdkClientException",
"Lambda.TooManyRequestsException"
]
}
],
"End": true
}
}
},
{
"StartAt": "Check Address",
"States": {
"Check Address": {
"Type": "Task",
"Parameters": {
"command": "CHECK_ADDRESS",
"data": {
"address.$": "$.application.address"
}
},
"Resource": "${DataCheckingFunctionArn}",
"Retry": [
{
"ErrorEquals": [
"Lambda.ServiceException",
"Lambda.AWSLambdaException",
"Lambda.SdkClientException",
"Lambda.TooManyRequestsException"
]
}
],
"End": true
}
}
}
],
"Catch": [
{
"ErrorEquals": [
"UnprocessableDataException"
],
"ResultPath": "$.error-info",
"Next": "Flag Application As Unprocessable"
}
],
"ResultPath": "$.checks",
"Next": "Review Required?"
},
"Review Required?": {
"Type": "Choice",
"Choices": [
{
"Variable": "$.checks[0].flagged",
"BooleanEquals": true,
"Next": "Pending Review"
},
{
"Variable": "$.checks[1].flagged",
"BooleanEquals": true,
"Next": "Pending Review"
}
],
"Default": "Approve Application"
},
"Pending Review": {
"Type": "Task",
"Resource": "arn:aws:states:::lambda:invoke.waitForTaskToken",
"Parameters": {
"FunctionName": "${FlagApplicationFunctionName}",
"Payload": {
"id.$": "$.application.id",
"flagType": "REVIEW",
"taskToken.$": "$$.Task.Token"
}
},
"ResultPath": "$.review",
"Retry": [
{
"ErrorEquals": [
"Lambda.ServiceException",
"Lambda.AWSLambdaException",
"Lambda.SdkClientException",
"Lambda.TooManyRequestsException"
]
}
],
"Next": "Review Approved?"
},
"Review Approved?": {
"Type": "Choice",
"Choices": [
{
"Variable": "$.review.decision",
"StringEquals": "APPROVE",
"Next": "Approve Application"
},
{
"Variable": "$.review.decision",
"StringEquals": "REJECT",
"Next": "Reject Application"
}
]
},
"Reject Application": {
"Type": "Task",
"Parameters": {
"id.$": "$.application.id"
},
"Resource": "${RejectApplicationFunctionArn}",
"Retry": [
{
"ErrorEquals": [
"Lambda.ServiceException",
"Lambda.AWSLambdaException",
"Lambda.SdkClientException",
"Lambda.TooManyRequestsException"
]
}
],
"End": true
},
"Approve Application": {
"Type": "Task",
"Parameters": {
"id.$": "$.application.id"
},
"Resource": "${ApproveApplicationFunctionArn}",
"Retry": [
{
"ErrorEquals": [
"Lambda.ServiceException",
"Lambda.AWSLambdaException",
"Lambda.SdkClientException",
"Lambda.TooManyRequestsException"
]
}
],
"End": true
},
"Flag Application As Unprocessable": {
"Type": "Task",
"Resource": "arn:aws:states:::lambda:invoke",
"Parameters": {
"FunctionName": "${FlagApplicationFunctionName}",
"Payload": {
"id.$": "$.application.id",
"flagType": "UNPROCESSABLE_DATA",
"errorInfo.$": "$.error-info"
}
},
"ResultPath": "$.review",
"Retry": [
{
"ErrorEquals": [
"Lambda.ServiceException",
"Lambda.AWSLambdaException",
"Lambda.SdkClientException",
"Lambda.TooManyRequestsException"
]
}
],
"End": true
}
}
}
EOF
sam build && sam deploy

cd ~/workshop-dir
aws lambda invoke --function-name sfn-workshop-SubmitApplication --cli-binary-format raw-in-base64-out --payload '{ "name": "Spock", "address": "123 Enterprise Street" }' out.json && cat out.json; echo
aws lambda invoke --function-name sfn-workshop-FindApplications --cli-binary-format raw-in-base64-out --payload '{ "state": "APPROVED" }' out.json >/dev/null && jq '.Items[] | {id, name, address, state}' out.json
ApproveApplicationFunction.
Open the latest execution and choose Review Required?.
checks as an array of two results.
To go further, read about the Map state to process a list of items, the service integrations that call more than 200 AWS services without Lambda, and Express workflows for short, high-volume workloads.