title: AWS Dynamodb not fetching data synchronously by node js
body: <p>I am new on node js dynamo db I wrote a node js sdk to fetch one row from a table ona dynamodb. It is fetching data <strong>correctly but not immediately</strong> for this I got error</p>
  
  <p>My code is below a simple code</p>
  
  <pre><code>var AWS = require("aws-sdk");
  
  var config = function(){
  
  AWS.config.update({region: 'us-east-1'});
  
  // Create the DynamoDB service object
  var ddb = new AWS.DynamoDB({apiVersion: '2012-08-10'});
  
  var params = {
    TableName: 'tblConfigs',
    // Key: {
    //   "id" : {S: "1"},
    // }
    ExpressionAttributeValues: {
     ":v1": {
       S: "1"
      }
    },
    FilterExpression: "id = :v1",
  };
  var v;
  var json = ddb.scan(params, function(err, data) {
    if (err) {
      console.log("Error", err);
    } else {
      v = data;
      // console.log(JSON.stringify(data.Item));
     // return JSON.stringify(data.Item);
    }
  });
  // if(v=="u")
  // for(var i=0;)
  
  v = v.Items[0];
  
  // for()
  
  var con = {
      "host": v.endpoint.S,
      "user": v.endpoint.username.S,
      "password": v.endpoint.password.S,
      "database": v.endpoint.database_name.S
  };
  
  return con;
  }
  </code></pre>
  
  <p>And I got the below error</p>
  
  <pre><code>&gt; config()
  TypeError: Cannot read property 'Items' of undefined
      at config (repl:31:7)
  </code></pre>
  
  <p>as v is undefined so it is giving the error but v is not undefined when I execute the code in node console it first time gave undefined next time it gave value</p>
  
  <p>like below</p>
  
  <pre><code>&gt; v
  { Items:
     [ { password: [Object],
         stage: [Object],
         username: [Object],
         id: [Object],
         endpoint: [Object],
         database_name: [Object] } ],
    Count: 1,
    ScannedCount: 1 }
  </code></pre>
  
  <p>how can I fetch the row immediately not after some time? IS there any good way in dynamodb I tried, get, getItem, scan, query all are giving data correctly but not immediately...Please suggest</p>