title: Algolia saveObject not called inside Lambda function using Serverless framework
body: <p>I'm using a Lambda function to index records into Algolia. I'm able to get the data via the <code>event</code> object. I'am running into a problem where the <code>saveObject</code> function of Algolia doesn't seem to call or it returns before finishing what it is doing. Bit hard to debug as well since I have to look at cloudwatch every time. I threw some <code>console.log</code>s here and there to see if the flow is correct. I'm kind of stuck here. Any help is much appreciated.</p>
  <p><strong>search.js</strong></p>
  <pre class="lang-js prettyprint-override"><code>'use strict';
  
  const algoliasearch = require('algoliasearch');
  
  const ALGOLIA_APP = 'appid';
  const ALGOLIA_KEY = 'algoliakey';
  const INDEX = 'indexname';
  
  const connectToIndex = (appId,apiKey,index) =&gt; {
    const client = algoliasearch(appId,apiKey);
    return client.initIndex(index);
  };
  
  const updateIndex = async (record) =&gt; {
    console.log('updating/replacing') //logs in cloudwatch
    const index = connectToIndex(ALGOLIA_APP,ALGOLIA_KEY,INDEX);
    console.log(record,index); //logs the record object and index object in cloudwatch
    index.saveObject(record)
    .then(()=&gt;{
      console.log('updated/replaced')  //doesn't log in cloudwatch + not indexed in algolia
      return;
    }
    ).catch((e) =&gt; {
      console.error(e);
      return;
    });
  }
  
  module.exports.algoliaIndexer = async (event, cb) =&gt; {
      try {
        const body = JSON.parse(event.Records[0].body);
        const record = {...restructuring body}; //record to index
        if (body.detail.operationType === 'update' || body.detail.operationType === 'replace'){
          updateIndex(record);
          console.log('done1') //logs in cloudwatch
        }
        console.log('done2') //logs in cloudwatch
        cb(null, responseObj('success', 200));
      } catch (e) {
        console.error(e);
        cb(null, responseObj(e.message, 500));
      }
    };
  </code></pre>
  <p><strong>handler.js</strong> contains the lambda function</p>
  <pre class="lang-js prettyprint-override"><code>'use strict';
  
  const search = require('./lib/search');
  
  let algoliaIndexer = (event, context, callback) =&gt; {
    context.callbackWaitsForEmptyEventLoop = false;
    search.algoliaIndexer(event, callback);
  };
  
  module.exports = {
    algoliaIndexer : algoliaIndexer 
  }
  </code></pre>
  <p><strong>EDIT</strong>
  I tried with <code>await updateIndex(record)</code> as well with no luck</p>