Created
November 2, 2015 23:13
-
-
Save sh0tt/d161984681d38717e9db 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 function'); | |
var AWS = require('aws-sdk'); | |
AWS.config.region = 'ap-northeast-1'; | |
var dynamodb = new AWS.DynamoDB(); | |
exports.handler = function(event, context) { | |
console.log(event); | |
if(event.id === null) { | |
context.fail("no such id"); | |
return; | |
} | |
var params = { | |
TableName: 'Tasks', | |
Key: { | |
"id": {"N": String(event.id)} | |
} | |
}; | |
dynamodb.getItem(params, function(err, data){ | |
if(err || data.Item === null) { | |
context.fail("data not found"); | |
return; | |
} | |
console.log(data); | |
var done = data.Item.done.BOOL; | |
console.log(done); | |
if(done) { | |
console.log("find one and delete..."); | |
dynamodb.deleteItem(params, function (err2, data2) { | |
err2 && console.log(err2); | |
var output = { | |
'id': event.id | |
}; | |
context.succeed(output); | |
console.log("delete " + output.id); | |
}); | |
} else { | |
context.fail("this Task doesn't complete yet"); | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment