Skip to content

Instantly share code, notes, and snippets.

@keithrozario
Created December 5, 2020 11:14
Show Gist options
  • Save keithrozario/a0e64252afe92b75e1a312284be2bc00 to your computer and use it in GitHub Desktop.
Save keithrozario/a0e64252afe92b75e1a312284be2bc00 to your computer and use it in GitHub Desktop.
Paginators for DynamoDB
import boto3
# Create your own session
my_session = boto3.session.Session(region_name="regionA", profile_name="profileA")
client = my_session.client('dynamodb')
paginator = client.get_paginator('scan')
# Option 1, paginate through paginator, a bit clunky, but possibly better performance
response_iterator = paginator.paginate(
TableName="kl.Klayers-prodp38.db"
)
for resp in response_iterator:
for item in resp['Items']:
print(f"{item['pk']}:{item['sk']}")
# Option 2: Build the full result, cleaner and allows for enumerator, but might need to store VAST data in memory
response_iterator = paginator.paginate(
TableName="kl.Klayers-prodp38.db"
).build_full_result()
for k, item in enumerate(response_iterator['Items']):
print(f"{k:05}.{item['pk']}:{item['sk']}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment