question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Utility for paginating through a BOTO3 dynamodb result for resource/tables

See original GitHub issue

Is your feature request related to a problem? Please describe.

When fetching a record set that requires pagination you have to implement something quite awkward. And if don’t naively, you could run into memory issues.

dynamodb.Table = boto3.resource("dynamodb")
large_table = dynamodb.Table("TableWithLotsOfData")

# Scan or Query with lots of data
response = large_table.scan()
items = response["Items"]

while "LastEvaluatedKey" in response:
        # Add ExclusiveStartKey to the original operation
	  response = table.scan(ExclusiveStartKey=response["LastEvaluatedKey"])
	  items.update(response["Items"])

or use DynamoDB.Paginator.Query.paginate

client = boto3.client("dynamodb")
paginator = client.get_paginator("scan")
params = {}

for page in paginator.paginate(params):
    # do something

Describe the solution you’d like

Build a custom iterator (much like how the Java AWS SDK has), which can automatically fetch more data as needed.

Describe alternatives you’ve considered

  • Building a small local library for this
  • doing the naive example.
  • Log an issue with boto3 library

Additional context

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
ran-isenbergcommented, Aug 8, 2021

@michaelbrewer I’ve been using PynamoDB for the past year and can confirm it’s awesome and makes life much easier with DynamdoDB.

1reaction
heitorlessacommented, Aug 6, 2021

Thanks for opening that.

That’s been an old request asking boto to port the pagination that boto3 DynamoDB client has onto the resource

https://github.com/boto/boto3/issues/2039

This is one among other suboptimal UX issues that makes Pynamodb be a better solution

https://pynamodb.readthedocs.io/en/latest/

Read more comments on GitHub >

github_iconTop Results From Across the Web

DynamoDB Table Resource should support Pagination for ...
Utility for paginating through a BOTO3 dynamodb result for resource/tables awslabs/aws-lambda-powertools-python#593.
Read more >
DynamoDB — Boto3 Docs 1.26.34 documentation - AWS
With DynamoDB, you can create database tables that can store and retrieve any amount of data, and serve any level of request traffic....
Read more >
DynamoDB pagination using Boto3 - Stack Overflow
However, we are unable to find a working sample of pagination. Here is what we did. import boto3 client_setting = boto3.client('dynamodb', ...
Read more >
Paginating table query results - Amazon DynamoDB
DynamoDB paginates the results from Query operations. With pagination, the Query results are divided into "pages" of data that are 1 MB in...
Read more >
DynamoDB Python Boto3 Query Cheat Sheet [14 Examples]
This cheat sheet covers the most important DynamoDB Boto3 query examples that you can use for your next DynamoDB Python project.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found