Skip to content

Instantly share code, notes, and snippets.

@sh0tt
Created November 2, 2015 23:10
Show Gist options
  • Save sh0tt/d9cf22d5e16cfdd760b6 to your computer and use it in GitHub Desktop.
Save sh0tt/d9cf22d5e16cfdd760b6 to your computer and use it in GitHub Desktop.
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