-
-
Save justinpitts/210e6456dfe50d21fd64 to your computer and use it in GitHub Desktop.
Short aws lambda sample program that puts an item into dynamodb
This file contains 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({apiVersion: '2012-08-10'}); | |
exports.handler = function(event, context) { | |
console.log("Event data:"); | |
console.log(JSON.stringify(event, null, ' ')); | |
dynamodb.listTables(function(err, data) { | |
console.log(JSON.stringify(data, null, ' ')); | |
}); | |
var tableName = "event-RSSI"; | |
var rectime = new Date().getTime().toString(); | |
dynamodb.putItem({ | |
"TableName": tableName, | |
"Item" : { | |
"coreid": {"S": event.coreid }, | |
"published_at": {"S": event.published_at }, | |
"rectime": {"S": rectime }, | |
"data": {"S": event.data } | |
} | |
}, function(err, data) { | |
if (err) { | |
context.done('error','putting item into dynamodb failed: '+err); | |
} | |
else { | |
console.log('great success: '+JSON.stringify(data, null, ' ')); | |
context.done('K THX BY'); | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment