KKeySync
← Back to quests
Quest · quest 14Johto · Advanced

Scrolling the Pokegear (Pagination)

The Johto Pokédex has 100 new Pokémon. Loading them all at once is slow and expensive. Instead, we fetch the first 10. DynamoDB returns a LastEvaluatedKey, telling us exactly where it stopped.

PaginationLastEvaluatedKey

Key takeaways

  • Pagination limits the amount of data returned in one call.
  • Limit controls items evaluated, not necessarily items returned after filtering.
  • Pass the LastEvaluatedKey back as the ExclusiveStartKey to get the next page.

Scrolling the Pokegear

When you scan or query, Limit caps the items DynamoDB evaluates before applying a filter. The returned item count can therefore be smaller. If there are more items, the response includes a LastEvaluatedKey. To get the next page, you start exactly where you left off by passing that key as the ExclusiveStartKey.

Pagination Requestjavascript

Interactive Challenge

Page 1 stopped at { Name: "Caterpie" }. Pass that key back as the ExclusiveStartKey so the next request resumes exactly where the last one ended.

Goal: Add ExclusiveStartKey: { Name: "Caterpie" } to fetch the next page.

Quick Quiz

Which parameter do you use to tell DynamoDB where to start reading the next page of results?

Make your choice to test your understanding. Submit to check, and if it's not quite right you can adjust and try again.