Created
November 2, 2015 23:10
-
-
Save sh0tt/d9cf22d5e16cfdd760b6 to your computer and use it in GitHub Desktop.
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 CreateTask function'); | |
var AWS = require('aws-sdk'); | |
AWS.config.region = 'ap-northeast-1'; | |
var db = new AWS.DynamoDB(); | |
exports.handler = function(event, context) { | |
if (event.id === null || | |
event.title === null || | |
event.title.length === 0 || | |
event.description === null) { | |
//other check may apply | |
context.fail(); | |
return; | |
} | |
var done = (event.done !== null) ? event.done : false; | |
var item = { | |
'id': { 'N': String(event.id) }, | |
'title': { 'S': event.title }, | |
'description': { 'S': event.description }, | |
'done': { 'BOOL': done }, | |
'createdAt': { 'S': new Date().getTime().toString() } | |
}; | |
var ddbRequest = db.putItem({ | |
'TableName': 'Tasks', | |
'Item': item | |
}, function(err, data) { | |
err && console.log(err); | |
var output = { | |
'id': String(event.id) | |
} | |
// we only return once the request succeeds | |
context.succeed(output); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment