Skip to content

Instantly share code, notes, and snippets.

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