Search code examples
amazon-dynamodbaws-sdkpartiql

DynamoDB PartiQL pagination using SDK


I'm currently working on pagination in DynamoDB using the JS AWS-SDK's executeStatement using PartiQL, but my returned object does not contain a NextToken (only the Items array), which is used to paginate. This is what the code looks like (pretty simple):

const statement = `SELECT "user", "id" FROM "TABLE-X" WHERE "activity" = 'XXXX'`;
const params = {Statement: statement};
try {
    const posted = await dynamodb.executeStatement(params).promise();
    return { posted: posted };
} catch(err) {
    throw new Error(err);
}

I was wondering if anyone has dealt with pagination using PartiQL for DynamoDB.

Could this be because my partition key is a string type?

Still trying to figure it out.

Thanks, in advance!


Solution

  • It turns out that if you want a NextToken DO NOT use version 2 of the AWS SDK for JavaScript. Use version 3. Version 3 will always return a NextToken, even if it is undefined.

    From there you can figure out your limits, etc (default limit until you actually get a NextToken is 1MB). You'll need to look into the dynamodb v3 execute statement method.

    You can also look into dynamodb paginators, which I've never used, but plan on studying.