0

I want to call more than one sql queries in sequence. I have tried with below code but getting timeout error:

    exports.handler = function (event, context, callback) {

   getNumber()
    .then(result1 => {
        // Use result1
        return getNumber1(); // (A)
    })
    .then(result2 => { // (B)
        console.log(result2);
        callback(null, "OK");
    })
    .catch(error => {
        console.log(error);
        callback(null, "OK");
    });
};

function getNumber() {

      return new Promise(function(resolve, reject) {

          connection.query("SELECT 1+1 as test ", (error, data) => {

            if (error) {
                reject(error);
            } else {
                resolve(data);
            }
            });
      }); 
    }

    function getNumber1() {

      return new Promise(function(resolve, reject) {

          connection.query("SELECT 1+2 as test ", (error, data) => {

            if (error) {
                reject(error);
            } else {
                resolve(data);
            }
            });
      }); 
    }

Here I'm getting 'Task timed out after 3.00 seconds' error. So anyone can help me to call connection.query synchronously.

4
  • Can you check whether it works for a single query? Commented May 22, 2018 at 18:44
  • @Ashan, single query, you mean to just call 'getNumber().then(....).catch(....) ? Commented May 22, 2018 at 19:46
  • Yes. Does it work? Just want to check whether the DB is accessible from Lambda. Commented May 22, 2018 at 19:47
  • @Ashan, I have updated my question by adding image for lambda function execution log. please check and kindly give you advice. Thanks! Commented May 22, 2018 at 19:56

1 Answer 1

0

This can be solved by chaining of AWS Lambda functions. So in this case, each function has to be separated into different lambda functions. Then call them in a chain.

Still, keep in mind that Lambda functions have the time limit and will exit. So you may need different architecture/AWS component to achieve this if the Lambda running time is more.

Invoke multiple aws lambda functions

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.