Created
March 28, 2016 01:21
-
-
Save leosilvadev/5851ab724f27fb9454bc 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 doc = require('dynamodb-doc'); | |
var dynamo = new doc.DynamoDB(); | |
function handleResult(context, event){ | |
return function(){ | |
var result = this.data || {Count:0, Items:[]}; | |
var data = {total:result.Count}; | |
data.items = result.Items.map(function(result){ | |
return {email:result.Email, tenant:result.Tenant}; | |
}); | |
context.succeed(data); | |
} | |
} | |
exports.handler = function(event, context) { | |
var tenant = event.tenant; | |
if(tenant) { | |
var params = { | |
TableName : "Users", | |
KeyConditionExpression: "#ten = :tenant", | |
ExpressionAttributeNames:{ | |
"#ten": 'Tenant' | |
}, | |
ExpressionAttributeValues: { | |
":tenant": tenant | |
} | |
}; | |
dynamo.query(params, handleResult(context, event)); | |
} else { | |
context.fail('Invalid parameters to find for the user!'); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment