title: Waiting for one callback to be done (to get data) before the other
body: <p>I am trying to get MedGuideURL to be used in the 2nd callback but it's value is empty.It seems the second callback is always happening before the first one is done. I am thinking of using Promise/Observable but is there an easier way? </p>
  
  <pre><code>var qrImage = require('qr-image');
  const AWS = require('aws-sdk');
  const docClient = new AWS.DynamoDB.DocumentClient({region:'us-west-2'});
  
  exports.handler = function(event, context, callback){
  
      var path = event.path;
      var drugId = path.replace(/\//g, '');
      var MedGuideURL = "";
  
      var params = {
      TableName: 'QRCodeInfo',
      Key: {
        "DrugId" : drugId
      }
    };
    docClient.get(params, function(err,data) {
      if (err) {
        callback(err,null);
      } else {
        console.log("The data is: "+ data.Item.MedGuideURL); //correct value
        callback(null,data);                                   
        MedGuideURL = data.Item.MedGuideURL;
      }
  
    });
  
    callback(null, sendRes(200, MedGuideURL)); //MedGuideURL is empty!
  };
  
  const sendRes = (status, body) =&gt; {
    //console.log(body);
    const svg_string = qrImage.imageSync(body, { type: 'svg', size: 10 });
    var response = {
      statusCode: status,
      headers: {
        "Content-Type": "image/svg+xml"
      },
      body: svg_string
    };
    return response;
  };
  </code></pre>