i have a silly problem that is driving me crazy. I have a AWS lambda function that has a call to Dynamo db.
i want to have the ddb.Scan operation into a function get the result and then pass it to the event, but i cannot return the result inside the function...
var aws = require('aws-sdk');
var ddb = new aws.DynamoDB();
function getName(userid) {
ddb.scan({
TableName: "Users",
ScanFilter: {
"userid":
{
"AttributeValueList": [
{"S": userid}
],
"ComparisonOperator": "EQ"
}
}
}, function (err, data) {
return data.Items[0].username;
});
};
exports.handler = function (event, context) {
var userid= '4vwe6jd56es59q';
var username = getName(userid);
context.succeed({success: true, username: username});
};
can someone help me understanding where i get lost?