How paginators work
Paginators are async generator functions. When called, they return an async iterable. Each iteration yields one page of results. Internally, the paginator makes the next request using the continuation token from the previous page, stopping when the service signals no more results remain. Use them with afor await...of loop:
Import pattern
Paginator functions are exported from the same service package as the client and commands. The function name is alwayspaginate followed by the operation name:
PaginatorConfig
Every paginator accepts aPaginatorConfig object as its first argument:
An instantiated service client. The paginator uses this to make requests.
The number of items to request per page. Passed as the
Limit (or equivalent) parameter to the underlying operation. The service may return fewer results than requested.Resume pagination from a specific point. Pass a token previously returned in a page’s
NextToken (or equivalent) field.Full example
ExclusiveStartTableName for ListTablesCommand).
Simplified syntax
You can inline the config object for a more concise form:Runtime requirements
Paginators use the Async Iteration protocol introduced in ES2018. They are supported in:- Node.js 10.x and later
- Chrome 63+, Firefox 57+, Safari 11.1+, Edge 79+
Early exit
Because paginators are lazy generators, you can break out of the loop early without fetching unnecessary pages:The paginator only requests the next page when the current iteration of the loop completes. No extra HTTP requests are made for pages you never consume.