Sub topic 3
Parallel Branches and Map Iteration
Assume you know JSON, basic Amazon States Language (ASL), IAM roles, and Lambda. This chapter focuses on workflow scaling, permissions, and operations.
Parallel branches and Map iteration
A Parallel state runs independent branches at the same time and joins their results. Use it when all branches can start together, such as charging a payment and reserving inventory.
A Map state repeats a sub-workflow for each item in an array. MaxConcurrency limits how many items run simultaneously. This protects downstream services from overload.
{
"StartAt": "ProcessOrders",
"States": {
"ProcessOrders": {
"Type": "Map",
"ItemsPath": "$.orders",
"MaxConcurrency": 5,
"ItemProcessor": {
"ProcessorConfig": { "Mode": "INLINE" },
"StartAt": "Validate",
"States": {
"Validate": {
"Type": "Pass",
"Result": { "valid": true },
"End": true
}
}
},
"End": true
}
}
}A Parallel state returns an array containing one result per branch. A Map state returns one result per input item. Design item processing to be idempotent, meaning repeating it does not create an incorrect duplicate.
Choosing Standard or Express workflows
Standard workflows support long-running executions, exactly-once state transitions, detailed history, and callback patterns. Express workflows suit high-volume, short-running processing. They use at-least-once execution semantics, so tasks should tolerate duplicates.
Execution roles and least-privilege permissions
The state machine execution role grants Step Functions permission to call services. Grant only required actions on specific resources, such as lambda:InvokeFunction for one Lambda function or sqs:SendMessage for one queue. Do not place broad administrator permissions on this role.
> callout note > A task can fail with AccessDeniedException even when the workflow definition is valid. Check the execution role and the target resource policy.
Debugging and large datasets
Use execution history to inspect inputs, outputs, retries, and errors. Send execution events to CloudWatch Logs for centralized searching. Enable X-Ray when you need traces across supported services.
Distributed Map reads items from sources such as Amazon S3 and runs child executions. Use it for datasets too large for an inline Map, while controlling concurrency and monitoring costs.
Deploying and testing
Validate ASL before deployment. Test success, timeout, retry, permission, and malformed-input paths with representative data. Deploy through a repeatable tool such as AWS CloudFormation, AWS CDK, or Terraform.
Exercise
Which state should process every element of an array while limiting concurrency?
Show answer
Use a Map state with ItemsPath pointing to the array and MaxConcurrency set to the safe limit.