Segment must be less than TotalSegments
TL;DR — In a parallel Scan, each worker sets Segment (its slice index) and TotalSegments (how many slices). DynamoDB requires 0 ≤ Segment < TotalSegments, and both must be supplied together. A Segment equal to or above TotalSegments is rejected. Assign each worker a distinct Segment from 0 to TotalSegments − 1.
What it means
ValidationException: The Segment parameter is out of range. Segment must be
less than TotalSegments (or: Segment must be greater than or equal to 0)A parallel scan divides the table into TotalSegments slices; each worker scans one slice identified by Segment. Valid Segment values are 0 through TotalSegments − 1. TotalSegments itself must be between 1 and 1,000,000. If you supply one without the other, or a Segment outside the range, DynamoDB rejects the call. It's an HTTP 400 ValidationException, client-side, and not retryable until the parameters are valid.
Why it happens
- Off-by-one segment assignment — with
TotalSegments = 4, usingSegmentvalues1..4instead of0..3. - Segment ≥ TotalSegments — a worker index that meets or exceeds the slice count.
- Only one of the pair supplied — passing
SegmentwithoutTotalSegments(or vice-versa); both are required for a parallel scan. - A dynamic worker pool mismatch —
TotalSegmentsset to a different value than the number of workers actually launched, so some workers get out-of-range indices.
How to fix it
- Assign segments
0toTotalSegments − 1— one distinctSegmentper worker. - Always pass both parameters together on every parallel-scan request.
- Keep
TotalSegmentsequal to the worker count and within1..1,000,000. - Use zero-based indexing when mapping a worker's ordinal to its
Segment.
Related errors
- Query key condition not supported — a related Query/Scan expression validation error.
- Filter Expression can only contain non-primary key attributes — a key attribute wrongly used in a Scan/Query filter.
- ValidationException (overview)