Skip to content

Instantly share code, notes, and snippets.

@ozbillwang
Forked from ShakataGaNai/awslambdasample.js
Last active March 19, 2017 01:23
Show Gist options
  • Save ozbillwang/faf82d68d3f13ade71dd to your computer and use it in GitHub Desktop.
Save ozbillwang/faf82d68d3f13ade71dd 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 = "OurBlogDemo";
var datetime = new Date().getTime().toString();
dynamodb.putItem({
"TableName": tableName,
"Item": {
"device": {
"S": event.device
},
"timedate": {
"N": datetime
},
"latitude": {
"N": event.lat
},
"longitude": {
"N": event.lon
}
}
}, function(err, data) {
if (err) {
context.fail('ERROR: Dynamo failed: ' + err);
} else {
console.log('Dynamo Success: ' + JSON.stringify(data, null, ' '));
context.succeed('SUCCESS');
}
});
}

way to zip files for lambda

zip -r abc.zip *.py *.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment