Created
September 29, 2015 01:58
-
-
Save jinman/2ac9e23ea748b2163cf7 to your computer and use it in GitHub Desktop.
LambdaToDynamoDB
This file contains hidden or 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
console.log('Loading event'); | |
var AWS = require('aws-sdk'); | |
var dynamodb = new AWS.DynamoDB(); | |
exports.handler = function(event, context) { | |
console.log("Request received:\n", JSON.stringify(event)); | |
console.log("Context received:\n", JSON.stringify(context)); | |
var tableName = "CommonDynamoDBTable"; | |
var datetime = new Date().getTime().toString(); | |
payload = event; | |
dynamodb.putItem({ | |
"TableName": tableName, | |
"Item" : { | |
"device_id": {"S": payload.device_id }, | |
"time": {"N": JSON.stringify(datetime) }, | |
"device": {"S": payload.device }, | |
"source": {"S": "from lambda" } | |
} | |
}, function(err, data) { | |
if (err) { | |
context.fail('ERROR: Putting item into dynamodb failed: '+err); | |
} | |
else { | |
console.log('great success: '+JSON.stringify(data, null, ' ')); | |
context.succeed('SUCCESS'); | |
} | |
}); | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment