Created
December 8, 2017 09:00
-
-
Save KazChe/ac94997b6e9cc48a6b61b90f2ce360e4 to your computer and use it in GitHub Desktop.
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 AWS = require('aws-sdk'); | |
var dynamodb = new AWS.DynamoDB({ apiVersion: '2012-08-10' }); | |
var docClient = new AWS.DynamoDB.DocumentClient() | |
var params = { | |
TableName: "mytable", | |
FilterExpression: "#schedule_type = :schedule_type_val", | |
ExpressionAttributeNames: { | |
"#schedule_type": "schedule_type", | |
}, | |
// we can narrow the returned result - still does a full-scan | |
ExpressionAttributeValues: { ":schedule_type_val": 'ByTime' } | |
// ExpressionAttributeValues: { ":schedule_type_val": 'Random' } | |
}; | |
var count = 0; | |
exports.handler = function(event, context) { | |
var tableName = tablename; | |
docClient.scan(params, onScan); | |
function onScan(err, data) { | |
if (err) { | |
console.error('Error JSON:', JSON.stringify(err,null,2)); | |
} | |
else { | |
data.Items.forEach(function(itemdata) { | |
console.log("Item :", ++count); | |
}); | |
if (typeof data.LastEvaluatedKey != "undefined") { | |
// console.log("Scanning for more..."); | |
params.ExclusiveStartKey = data.LastEvaluatedKey; | |
docClient.scan(params, onScan); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment