AWS Dynamodb scan using ExclusiveStartKey option

amazon-dynamodb, node.js

Solution

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);
    }
})

}

Problem

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."

Original source