/* This test inserts two rows of data into table "atest1" and one row of data into table "atest2" using a single call. */
/*
AWS DYNAMO
*/
var AWS = require("aws-sdk");
var batClient = new AWS.DynamoDB();
var params = {};

exports.handler = function(event, context) {
    params = {
		RequestItems: {
			"atest1": [
			    {
				    PutRequest: {
					    Item: {
						    "id": { "N": "1" },
						    "txtTitle": { "S": "pancakes" }
					    }
					}
			    },
			    {
				    PutRequest: {
					    Item: {
						    "id": { "N": "2" },
						    "txtTitle": { "S": "waffles" }
					    }
					}
			    }
			],
			"atest2": [
			    {
				    PutRequest: {
					    Item: {
						    "id": { "N": "1" },
						    "txtDescription": { "S": "Pancakes are good but waffles are better." }
					    }
				    }
			    }
			]
		},
		ReturnConsumedCapacity: "NONE",
		ReturnItemCollectionMetrics: "NONE"
	};
	batClient.batchWriteItem(params, function(err, data) {
		if (err) {
			/* Dynamo Error */
			context.done(
				null,
				{
				"Result": JSON.stringify(err, null, 2)
				}
			);
		}
		else {
			/* Operation Completed */
			context.done(
				null,
				{
				"Result": "Operation succeeded."
				}
			);
		}
	});
};
