Last active
September 25, 2020 21:14
-
-
Save taylorbryant/eda7b5f70325fb26f4400d263555069b to your computer and use it in GitHub Desktop.
Get all items from a DynamoDB table using the scan operation
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
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]; | |
}); | |
} |
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 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