How to use pagination in SimpleDB?

82 views Asked by At

I just started using SimpleDB, but here I got stuck in applying pagination. I need rows from 5 to 15. But, based on my search I found that the below query will not work here (as it works for SQL):

SELECT * from `DomainName` limit 5, 10;

So I tried the pagination feature here:

import boto3, json

def lambda_handler(event, context):
    session = boto3.session.Session()
    client = session.client("sdb", region_name="us-east-1")

    paginator = client.get_paginator('select')
        
    page_iterator = paginator.paginate(
                        SelectExpression=f"SELECT * FROM `DomainName`",
                        ConsistentRead=True,
                        PaginationConfig={'MaxItems': 10, 'StartingToken': token}
                                      )
  
    selected = []
    for page in page_iterator:
        for pg in page["Items"]:
            selected.append(pg)
            
        # token = page['NextToken']
           
    return{
            'statusCode': 200,
            'headers': {
                'Access-Control-Allow-Origin': '*',
                'Access-Control-Allow-Methods': '*'
            },
        'body': json.dumps({'message': selected})
    }

Please suggest how to achieve this. I already read things about Token, NextToken String, but was not able to implement them.

1

There are 1 answers

0
Coin Graham On

Drop the "Pagination Config" from your paginate command and try running your code without it. See more instructions on using pagination here