For my recent project, I am trying to get data from dynamodb. And it seems everything working fine except I add "exclusiveStartKey" option to my parameters.
Below is my code.
function scanDataFromDB(datetime) {
let params = {
TableName: TABLE_NAME,
IndexName: "main-index",
Select: "ALL_ATTRIBUTES",
ExclusiveStartKey: {
"message_id": { "S": "20161011175258875925351560"}
},
ExpressionAttributeNames: {
"#f_up": "date_updated"
},
ExpressionAttributeValues: {
":s_time": "2016-10-11 00:00:00",
":e_time": "2016-10-11 23:59:59"
},
FilterExpression: "#f_up between :s_time and :e_time",
ScanIndexForward: "true"
};
console.log(params);
docClient.scan(params, function(err, data) {
if(err) {
console.log(JSON.stringify(err, null, 2));
//callback(err, null);
} else {
console.log(JSON.stringify(data, null, 2));
//callback(null, err);
}
})
}
This keep returning "The provided starting key is invalid." Any advice or help is welcome.
I found out the problem. It took me almost a week. If there is a sort key with partition key, "ExclusiveStartKey" Options must indicate both partition key and sort key.
function scanDataFromDB(datetime) {
let params = {
TableName: TABLE_NAME,
IndexName: "main-index",
Select: "ALL_ATTRIBUTES",
ExclusiveStartKey: {
"message_id": "20161012114321726034249204",
"date_updated": "2016-10-12 11:44:09"
},
ExpressionAttributeNames: {
"#f_up": "date_updated"
},
ExpressionAttributeValues: {
":s_time": "2016-10-11 00:00:00",
":e_time": "2016-10-11 23:59:59"
},
FilterExpression: "#f_up between :s_time and :e_time",
ScanIndexForward: "true"
};
console.log(params);
docClient.scan(params, function(err, data) {
if(err) {
console.log(JSON.stringify(err, null, 2));
//callback(err, null);
} else {
console.log(JSON.stringify(data, null, 2));
//callback(null, err);
}
})
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With