Created
June 4, 2021 09:20
-
-
Save avtaniket/456d8d23e0ff66dbd9d5797a2b321284 to your computer and use it in GitHub Desktop.
Query (and Scan) DynamoDB Pagination
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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