Skip to content

Instantly share code, notes, and snippets.

@taylorbryant
Last active September 25, 2020 21:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taylorbryant/eda7b5f70325fb26f4400d263555069b to your computer and use it in GitHub Desktop.
Save taylorbryant/eda7b5f70325fb26f4400d263555069b to your computer and use it in GitHub Desktop.
Get all items from a DynamoDB table using the scan operation
function deepScan(scanOperationParams, dynamodbClient) {
return dynamodbClient
.scan({
ConsistentRead: true,
...scanOperationParams,
})
.promise()
.then(async ({ Items, LastEvaluatedKey }) => {
if (!LastEvaluatedKey) {
return Items;
}
const additionalItems = await getAllItemsFromTable({
...scanOperationParams,
ExclusiveStartKey: LastEvaluatedKey,
});
return [...Items, ...additionalItems];
});
}
const DynamoDB = require(`aws-sdk/clients/dynamodb`);
const deepScan = require(`./deep-scan`);
const dynamodb = new DynamoDB.DocumentClient({
apiVersion: `2012-08-10`,
region: `us-east-1`,
});
function getComicBooksByIllustratorName(illustratorName) {
return deepScan(
{
TableName: `ComicBooks`,
ExpressionAttributeValues: { ":illustratorName": illustratorName },
FilterExpression: `illustratorName = :illustratorName`,
},
dynamodb
);
}
getComicBooksByIllustratorName(`Frank Miller`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment