Last active
November 13, 2015 16:02
-
-
Save MizukiSonoko/7ffd05de6b0c42ad395d to your computer and use it in GitHub Desktop.
[Lambda's code] REST API using DynamoDB.
This file contains 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'); | |
var dynamo = new AWS.DynamoDB({region: 'ap-northeast-1'}); | |
exports.handler = function(event, context) { | |
var id = event.id || "EXCEPT_VALUE"; | |
delete event.id; | |
var params = { | |
TableName: 'Test', | |
"IndexName": "id-index", | |
"KeyConditionExpression": "#id = :id", | |
ExpressionAttributeNames : { | |
"#id":"id" | |
}, | |
"ExpressionAttributeValues":{ | |
":id":{"S":id} | |
} | |
}; | |
var operation = event.operation; | |
delete event.operation; | |
dynamo.query(params, function(err, data){ | |
context.succeed(JSON.parse(JSON.stringify(data, function(key, value) { | |
if (value.hasOwnProperty('S')) { | |
return value['S']; | |
} | |
if (value.hasOwnProperty('BOOL')) { | |
return value['BOOL']; | |
} | |
if (value.hasOwnProperty('N')) { | |
return value['N']; | |
} | |
return value; | |
}) | |
)); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment