title: How to return the query result from a function in AWS DynamoDB - JS lambda
body: <p>i have a silly problem that is driving me crazy. I have a AWS lambda function that has a call to Dynamo db.</p>
  
  <p>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...</p>
  
  <pre><code>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}); 
  
  
  };
  </code></pre>
  
  <p>can someone help me understanding where i get lost?</p>