AWS Lambda stops working if it breaks once

Viewed 303

I have a lambda with 5s timeout. Here is a simple lambda that I upload:

exports.handle = function(event, context, callback) {
    if (Math.random() < 0.5) {
        callback(null, "done");
    } else {
        setTimeout(() => callback(null, "delayed"), 6000);
    }
};

As you can see, 50% of the times it should just return 'done' but the other 50% of the time, there should be a delay that is higher than the timeout and I expect to get a timeout error.

Problem is, once I get the timeout error, I will ALWAYS get a timeout error. The lambda stops working.

How come? I even tried context.callbackWaitsForEmptyEventLoop = false without any success

0 Answers
Related