/* Reference: http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_BatchGetItem.html */
/* Scenario: Query one table multiple times */
/*
AWS DYNAMO
*/
var AWS = require("aws-sdk");
var batClient = new AWS.DynamoDB();
var params = {};
var result1 = "";
        
exports.handler = function(event, context) {
    /* Create batchGetItem Query */
    params = {
        "RequestItems": {
            "UserAccountServiceChoicesMain": { // Table 1
                "Keys": [
                    {
                        "UserAccountServiceChoicesID": { "N":"1" } // Column and value to match
                    },
                    {
                        "UserAccountServiceChoicesID": { "N":"2" } // Column and value to match
                    }
                ],
                "ProjectionExpression": "UserAccountServiceChoicesID,ChoicePrice" // Column values to return
            }
        }
    };
    /* Perform Dynamo Call */
    batClient.batchGetItem(params, function(err, data) {
        if (err) {
            /* DynamoDB error */
            context.done(
                null,
                {
                    "Hubub": "Error JSON: " + JSON.stringify(err, null, 2)
                }
            );
        } else {
            /* Get results of querying Table 1 */
            data.Responses.UserAccountServiceChoicesMain.map(function(row) {
                /* Each match is a row of results; in this case there will be 2 rows */
                var tmp_UserAccountServiceChoicesID = row.UserAccountServiceChoicesID.N;
                var tmp_ChoicePrice = row.ChoicePrice.N;
                /* Put into string */
                result1 = result1 + "UserAccountServiceChoicesID = " + tmp_UserAccountServiceChoicesID + ", ChoicePrice = " + tmp_ChoicePrice + "...";
            });
            /* Generate Response */
            context.done(
                null,
                {
                    "result1": result1
                }
            );
        }
    });
};
