Pagination, waiters and idempotency
Follow the continuation token
A list call may return only part of a collection. The server continuation token is opaque: pass it unchanged into the matching operation with the same scope and filters. S3 ListObjectsV2 accepts ContinuationToken as input and returns NextContinuationToken when there is another page. A truncated page may have no matching results after filtering; continue using the token, not the item count. An SDK paginator uses operation models to follow tokens; PageSize asks for service page size while MaxItems limits the SDK aggregate. A paginator resume token can be different from a raw service token. CLI --no-paginate returns only the initial service page, whereas --no-cli-pager disables the local display pager.
Bound a paginated workflow
The fictional inventory has a first page containing alpha and a continuation token p2, followed by beta and gamma. The expected result is three keys in two calls. Store durable checkpoints only after downstream work for a page is committed; replay must be safe if the process crashes before checkpointing. Do not assume a listing is a frozen snapshot during concurrent changes. The local paginator rejects repeated tokens, malformed pagination and a page cap. A partial failure raises an error rather than returning an apparently complete list. In a production stream, mark incomplete scans explicitly and scope checkpoints to the exact request. CLI JSON queries operate on the aggregated response, whereas text output can apply the query per page; a first-item query can therefore yield different counts.
[ { "Contents": [ { "Key": "alpha" } ], "IsTruncated": true, "NextContinuationToken": "p2" }, { "Contents": [ { "Key": "beta" }, { "Key": "gamma" } ], "IsTruncated": false }]Wait for a state, not an arbitrary sleep
A waiter polls a documented operation for success or failure conditions. EC2 instance_running, for example, waits for the running state, not an application health check. Set Delay and MaxAttempts according to the waiter contract, plus a workflow deadline. Eventual consistency means a successful mutation may not immediately appear in a subsequent read; a documented transient not-found during creation can be retried under a bounded waiter, whereas arbitrary missing resources should not be retried forever. The local waiter uses the synthetic sequence pending, pending, ready; a failed state terminates immediately and a never-ready resource exhausts its poll budget.
Make retries safe for mutations
A timeout does not tell you whether the server committed a write. For operations supporting idempotency, persist a stable client token for one logical request, reuse the same parameters on retry and respect the service-specific token scope and retention. EC2 RunInstances supports a client token; its regional or zonal scope depends on request parameters. A different request with the same token can cause IdempotentParameterMismatch. Do not generate a fresh token per attempt or assume all operations support one. Without a verified idempotency contract, reconcile state after an ambiguous failure before retrying. The lab records an immutable result for a synthetic token and rejects changed parameters; it is not the EC2 idempotency implementation.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Pagination, waiters and idempotency — knowledge check
Reason about bounded, safe SDK automation.
A page contains no matching results but has a continuation token. What next?
What does MaxItems constrain in an SDK paginator?
When should a page checkpoint be committed?
What does instance_running prove?
How should an idempotency token be reused?