Forked from deepanprabhu/gist:fbb406c3432c19eafe78a4b44e6a4b23
Created
December 11, 2019 09:46
-
-
Save ruselknow/b37351c89407d0e97addc92b3ef7b55e to your computer and use it in GitHub Desktop.
Concise Recursive DynamoDB Scan - Large Table - Using ExclusiveStartKey and LastEvaluatedKey - NodeJS
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
| let params = { | |
| TableName: 'xxx', | |
| Limit: 50 // Configure based on needs | |
| }; | |
| let aItems = []; | |
| const recursiveScan = (params) => { | |
| return client.scan(params).promise().then((data) => { | |
| // Simple Changes to input, optional | |
| let newItems = data.Items.map((item) => { | |
| return item; | |
| }); | |
| aItems = aItems.concat(newItems); | |
| if(data.LastEvaluatedKey != null){ | |
| params.ExclusiveStartKey = data.LastEvaluatedKey; | |
| // Recursive call, as deep as we can loop ! | |
| return recursiveScan(params); | |
| } | |
| return Promise.resolve(aItems); | |
| }).then((items) => { | |
| if(items != null && items.length != null) | |
| console.log("Final List : " + items.length); | |
| }).catch((error) => { | |
| console.log(error); | |
| console.log(JSON.stringify(error)); | |
| }); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment