dynamodb-parallel-scanner
This is just a small utility for performing parallel scans
on a DynamoDB
table. This module allows for scans to be executed
in parallel with an api that prevents too much memory from
being pulled into memory.
Installation
npm i dynamodb-parallel-scanner
Usage
This module exposes a parallelScan
function that accepts a
DynamoDB
documentClient, a base ScanInput
, the number of totalSegments
to break split up the scan with, and some hooks for reacting to results
and errors.
Example Usage:
import DynamoDB from 'aws-sdk/clients/dynamodb';
const dynamodb = new DynamoDB();
const documentClient = new DynamoDB.DocumentClient({ service: dynamodb });
await parallelScan({
documentClient,
scanInput: {
TableName: 'my-table',
},
onResults: async (context, scanResult) => {
console.log(context.segment);
try {
await doSomethingWithItems(scanResult.Items);
} catch (err) {
console.error(err);
context.abort();
}
},
onError: (context, err) => {
console.log(context.segment);
console.error(err);
context.abort();
},
totalSegments: 5,
attemptOptions: {
maxAttempts: 2,
},
});
Testing
This module will assume you have docker
and docker-compose
installed.
To run tests, simply run npm test
. This will start a dynamodb container and
run tests against that locally. To close the container,
run docker-compose down
or npm docker:down
.