Created
November 2, 2015 23:07
-
-
Save sh0tt/d56e6a3c5f06bf41bc32 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
var AWS = require('aws-sdk'); | |
AWS.config.region = 'ap-northeast-1'; | |
var db = new AWS.DynamoDB(); | |
exports.handler = function(event, context) { | |
console.log(event); | |
var ddbRequest = null; | |
var formatOutput = function(data) { | |
var output = []; | |
for ( var i = 0; i < data.Items.length; i++ ) { | |
var item = data.Items[i]; | |
output.push({ | |
'id' : item.id.N, | |
'title' : item.title.S, | |
'description' : item.description.S, | |
'done' : item.done.BOOL, | |
'createdAt' : item.createdAt.S, | |
'updatedAt' : item.updatedAt.S | |
}); | |
} | |
return output; | |
} | |
var params = { | |
TableName: 'Tasks', | |
Select: "ALL_ATTRIBUTES" | |
}; | |
ddbRequest = db.scan(params, function(err, data){ | |
err && console.log(err); | |
console.log('query'); | |
context.succeed(formatOutput(data)); | |
}); | |
ddbRequest.send(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment