AWS Lambda timeout when quering Couchbase

Problem:

  • Lambda timing out, (setting it to 15 sec), however it logs everything in Cloudwatch (console.log())

I get results from couchbase, but the lambda callback never seems to be called.

bucket.query(query, function (err, rows, meta) {
        // all these are successfully shown in Cloudwatch
        console.log("rows", rows);
        console.log("err", err);
        console.log(meta);

        if (rows) {
            response = {
                statusCode: 200,
                body: JSON.stringify({
                    data: rows
                }),
            };
        } else {
            response = {
                statusCode: 200,
                body: JSON.stringify({
                    data: []
                }),
            };
        }
        // this never gets called
        callback(null, response);
    });
 

Everything works locally, running the script it immediately responds gracefully, no timeout. Locally I npm install on my Mac. For the lambda I run a Amazon Linux EC2 instance, and npm install from there, download the node_modules folder with the bindings, and add them to my lambda package manually.

However I found a solution (? )/ workaround, I can close the bucket connection,

bucket.query(query, function (err, rows, meta) {
        // all these are successfully shown in Cloudwatch
        console.log("rows", rows);
        console.log("err", err);
        console.log(meta);

        if (rows) {
            response = {
                statusCode: 200,
                body: JSON.stringify({
                    data: rows
                }),
            };
        } else {
            response = {
                statusCode: 200,
                body: JSON.stringify({
                    data: []
                }),
            };
        }
        // now it works
        bucket.disconnect();
        callback(null, response);
    });

But I haven’t seen this approach anywhere in the documentation ? Furthermore, its strange it works locally super fast and smooth without it, but not when executing the lambda, is it a bug or could someone explain how it should be done properly.

Let me know if you need any further information.

What version of the SDK do you use? Could you export LCB_LOGLEVEL=5 environment variable and post the output here?