-
-
Save hemanthkodandarama/3c19545d703f95f3870d5ec7607647d9 to your computer and use it in GitHub Desktop.
A short snippet for scanning AWS DynamoDB table with AWS SDK and Promise
This file contains 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
var params = { | |
TableName: 'MYTABLE', | |
FilterExpression: 'contains (myKey , :query)', | |
ExpressionAttributeValues: { | |
':query': query | |
} | |
} | |
var dynamoScan = new Promise(function(resolve, reject) { | |
var results = [] | |
var onScan = (err, data) => { | |
if (err) { | |
return reject(err) | |
} | |
results = results.concat(data.Items) | |
if (typeof data.LastEvaluatedKey != 'undefined') { | |
params.ExclusiveStartKey = data.LastEvaluatedKey | |
docClient.scan(params, onScan) | |
} else { | |
return resolve(results) | |
} | |
} | |
docClient.scan(params, onScan) | |
}) | |
dynamoScan | |
.then((results) => { | |
res.json(results) | |
}) | |
.catch((err) => { | |
Logger.error(err) | |
return next(err) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment