Sub topic 13
Processing large datasets with Distributed Map
This chapter assumes you know inline Map states, Retry and Catch, and the Standard and Express workflow types from earlier chapters. You should also be comfortable with S3 and basic IAM policies.
Why inline Map is not enough
An inline Map runs its iterations inside the parent execution. That causes three limits:
- The input array must fit in the 256 KB state payload limit.
- Concurrency tops out at about 40 iterations.
- Every iteration's events go into the parent's execution history, which is capped at 25,000 events for Standard workflows.
Distributed Map removes these limits. It reads items directly from S3 and starts a separate child workflow execution for each item or batch of items. It can run up to 10,000 child executions at the same time.
A working definition
This state reads a CSV file from S3, groups rows into batches of 100, and sends each batch to a Lambda function. The rows from a batch arrive in the function's event under Items.
{
"StartAt": "ProcessOrders",
"States": {
"ProcessOrders": {
"Type": "Map",
"ItemReader": {
"Resource": "arn:aws:states:::s3:getObject",
"ReaderConfig": {
"InputType": "CSV",
"CSVHeaderLocation": "FIRST_ROW"
},
"Parameters": {
"Bucket": "my-data-bucket",
"Key": "orders/2026-11.csv"
}
},
"ItemBatcher": {
"MaxItemsPerBatch": 100
},
"MaxConcurrency": 200,
"ToleratedFailurePercentage": 5,
"ItemProcessor": {
"ProcessorConfig": {
"Mode": "DISTRIBUTED",
"ExecutionType": "EXPRESS"
},
"StartAt": "HandleBatch",
"States": {
"HandleBatch": {
"Type": "Task",
"Resource": "arn:aws:states:::lambda:invoke",
"Parameters": {
"FunctionName": "arn:aws:lambda:us-east-1:123456789012:function:HandleBatch:$LATEST",
"Payload.$": "$"
},
"OutputPath": "$.Payload",
"End": true
}
}
},
"ResultWriter": {
"Resource": "arn:aws:states:::s3:putObject",
"Parameters": {
"Bucket": "my-data-bucket",
"Prefix": "results/2026-11"
}
},
"End": true
}
}
}The parts that differ from inline Map
- ItemReader replaces
ItemsPath. It supports CSV, JSON, JSONL, a list of S3 objects, and S3 inventory manifests. - Mode
DISTRIBUTEDmakes each iteration a child workflow execution.ExecutionTypecan beSTANDARDorEXPRESS. Pick Express for short, idempotent, high-volume work. Pick Standard when you need long runtimes, exactly-once semantics, or per-child history. - ItemBatcher groups items so one child handles many. Batching cuts the number of executions and the cost of per-execution overhead.
- MaxConcurrency caps parallel children. Set it to protect downstream systems, because a Lambda function or database can be throttled well before Step Functions reaches its limit.
- ToleratedFailurePercentage (or
ToleratedFailureCount) lets the Map succeed when a few children fail. Without it, the first child failure fails the whole state. - ResultWriter stores child results in S3. Without it, the combined results must fit in 256 KB.
Common errors
- Missing permissions. The execution role needs
s3:GetObjectands3:ListBucketfor the source,s3:PutObjectfor the results, andstates:StartExecutionon the state machine itself, because the parent starts the children. - Forgetting the batch shape. With
ItemBatcher, your processor receives an object with anItemsarray, not a single row. - Oversized child output. Each child still returns data through the 256 KB limit. Write large outputs to S3 from the child and return a pointer.
- Non-idempotent Express children. Express workflows run at-least-once, so a batch may be processed twice.
Exercise
Your Distributed Map reads a 5 GB JSONL file, and the Lambda function in each child calls a database that handles about 50 concurrent connections. Which two settings do you adjust, and why?
Show answer
Lower MaxConcurrency to roughly 50 or below, so that the number of parallel children does not exceed what the database can handle. Raise MaxItemsPerBatch (ItemBatcher) so each child processes more rows. This gives fewer executions and less connection pressure.