Last active
October 28, 2017 15:31
-
-
Save AjeetK/4ada4cfef19ce2d12203a0b18e9e92d0 to your computer and use it in GitHub Desktop.
lambda function with dynamodb
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 = "myinfo"; | |
var datetime = new Date().getTime().toString(); | |
dynamodb.putItem({ | |
"TableName": tableName, | |
"Item": { | |
"name": { | |
"S": event.name | |
}, | |
"timedate": { | |
"N": datetime | |
} | |
} | |
}, 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