Skip to content

Instantly share code, notes, and snippets.

@Neolusis
Last active June 27, 2016 09:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Neolusis/aaeb795c2bce7de37dcf5e004401fb80 to your computer and use it in GitHub Desktop.
Save Neolusis/aaeb795c2bce7de37dcf5e004401fb80 to your computer and use it in GitHub Desktop.
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 = "SigfoxStore";
var datetime = new Date().getTime().toString();
dynamodb.putItem({
"TableName": tableName,
"Item": {
"device": {
"S": event.device
},
"timedate": {
"N": datetime
},
"temperature": {
"N": event.temperature
},
"humidity": {
"N": event.humidity
}
}
}, function(err, data) {
if (err) {
context.fail('ERROR: Dynamo failed: ' + err);
} else {
console.log('Dynamo 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