Skip to content

Instantly share code, notes, and snippets.

@vladholubiev
Created November 11, 2022 10:47
Show Gist options
  • Save vladholubiev/ef8795e868656dcc6db6e53ef9811af9 to your computer and use it in GitHub Desktop.
Save vladholubiev/ef8795e868656dcc6db6e53ef9811af9 to your computer and use it in GitHub Desktop.
const {parallelScanAsStream} = require('@shelf/dynamodb-parallel-scan');
(async () => {
const stream = await parallelScanAsStream(
{
TableName: 'files',
FilterExpression: 'attribute_exists(#fileSize)',
ExpressionAttributeNames: {
'#fileSize': 'fileSize',
},
ProjectionExpression: 'fileSize',
},
{concurrency: 1000, chunkSize: 10000, highWaterMark: 10000}
);
for await (const items of stream) {
console.log(items); // 10k items here
// do some async processing to offload data from memory
// and move on to cosuming the next chunk
// scanning will be paused for that time
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment