Algolia saveObject not called inside Lambda function using Serverless framework

Solution 1:

I'am running into a problem where the saveObject function of Algolia doesn't seem to call or it returns before finishing what it is doing.

That's the issue. You are not waiting for the saveObject function to finish (return the result). To do this you need to await for your async functions return (the concept is called async/await).

So, try changing this line:

updateIndex(record);

to

await updateIndex(record);

This should fix the issue.

Furthermore, you are using an async handler with a callback. That might also break something. You either use an async handler OR a callback, not both.

Try the following handler signature:

module.exports.algoliaIndexer = async (event) {
  ... your code ...
}

Relevant documentation: https://docs.aws.amazon.com/lambda/latest/dg/nodejs-handler.html