Skip to content

Instantly share code, notes, and snippets.

@avtaniket
Created June 4, 2021 09:20
Show Gist options
  • Save avtaniket/456d8d23e0ff66dbd9d5797a2b321284 to your computer and use it in GitHub Desktop.
Save avtaniket/456d8d23e0ff66dbd9d5797a2b321284 to your computer and use it in GitHub Desktop.
Query (and Scan) DynamoDB Pagination
const getAll = async () => {
let result, accumulated, ExclusiveStartKey;
do {
result = await DynamoDB.query({
TableName: argv.table,
ExclusiveStartKey,
Limit: 100,
KeyConditionExpression: 'id = :hashKey and date > :rangeKey'
ExpressionAttributeValues: {
':hashKey': '123',
':rangeKey': 20150101
},
}).promise();
ExclusiveStartKey = result.LastEvaluatedKey;
accumulated = [...accumulated, ...result.Items];
} while (result.Items.length || result.LastEvaluatedKey);
return accumulated;
};
getAll()
.then(console.log)
.catch(console.error);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment