Skip to content

Instantly share code, notes, and snippets.

@justinpitts
Forked from markusklems/lambda-dynamo
Last active August 29, 2015 14:25
Show Gist options
  • Save justinpitts/210e6456dfe50d21fd64 to your computer and use it in GitHub Desktop.
Save justinpitts/210e6456dfe50d21fd64 to your computer and use it in GitHub Desktop.
Short aws lambda sample program that puts an item into dynamodb
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