0
votes

I have a Lambda function that receives a message from SNS and uses a custom module that queries an external database and outputs calculations to the database. The module works fine: the Lambda has internet access via VPC and successfully connects to the database and outputs the desired data to the database, but I am still getting the error "Task timed out after 3.00 seconds." The module itself uses sequelize, async/await, and promises.

I increased the max timeout and the only difference was that the number of seconds in the error message increased to the timeout limit. I tried reserving concurrency and the error persists. Every part of my function works great other than the fact that the callback never resolves, producing a timeout error. I have tried running the function with and without the "context.callbackWaitsForEmptyEventLoop" statement, running it with the statement only makes the code return before any of the rating engine function is completed. Here is the rating engine code: https://github.com/elizajanus/rating-engine-module

Is it possible that the database connection is not closing within my custom module and preventing the code from fully completing the imported function? Or could it be something else? This issue may be connected: https://github.com/sequelize/sequelize/issues/8468

const {RatingEngine} = require('./rating-engine');


exports.handler = (event, context, callback) => {
    const message = event.Records[0].Sns.Message;
    RatingEngine(message, message.d_customer_id, 
      message.d_total_distance_travelled); 
    callback(null, 'move record created in database');
};
1
Your code is hanging on RatingEngine, you need to post the code from the RatingEngine otherwise its impossible to discover where its hanging inside that function. - justcode
I just realized that I was missing capitalization in context.callbackWaitsForEmptyEventLoop = false. Correcting this only made the function skip almost all of my custom module code and return the callback before any of it was completed, so scratch that line. I'll link to a censored version of the custom module on github in the next ten min or so. I think this may have something to do with my problem as well: github.com/sequelize/sequelize/issues/8468 - Eliza Janus
here is the code for the RatingEngine function used in the Lambda (apologies in advance, this is in the "make it work" stage): github.com/elizajanus/rating-engine-module - Eliza Janus
the RatingEngine function itself is in index.js - Eliza Janus
Your code is very extensive, shouldnt you reject() on errors? I also suggest you to add aws x ray and save messages according to the steps reached inside that function it will help you to discover where is the problem. - justcode

1 Answers

0
votes

@Eliza Janus, you can test your code locally with https://www.npmjs.com/package/lambda-local, this will help you you to better identify the problem debugging the code.