I've been using AWS Lambda and testing with SAM local for nearly a year with no major issues. However, I've written a Lambda function which modifies some files with the S3 API.
The function ends with a 502: Invalid lambda response received: Lambda returned <class 'NoneType'> instead of dict
This is before my function has had a chance to finish... I've managed to condense the code to the following:
exports.handler = async (event, context) => {
console.log("Goldi");
await fish(event, context);
console.log("Locks");
return { statusCode: 200, body: "Finished!" };
};
No matter whether I run this in SAM Local or upload to AWS Lambda, I get this output:
START RequestId: 6a30e157-3e9b-465e-a945-3e9f7fa2cd7e Version: $LATEST
2022-01-12T18:36:27.601Z 6a30e157-3e9b-465e-a945-3e9f7fa2cd7e INFO Goldi
2022-01-12T18:36:27.603Z 6a30e157-3e9b-465e-a945-3e9f7fa2cd7e INFO Some output from fish()...
END RequestId: 6a30e157-3e9b-465e-a945-3e9f7fa2cd7e
REPORT RequestId: 6a30e157-3e9b-465e-a945-3e9f7fa2cd7e Init Duration: 0.18 ms Duration: 12600.03 ms Billed Duration: 12700 ms Memory Size: 512 MB Max Memory Used: 512 MB
Invalid lambda response received: Lambda returned <class 'NoneType'> instead of dict
2022-01-12 18:36:38 127.0.0.1 - - [12/Jan/2022 18:36:38] "POST / HTTP/1.1" 502 -
I've configured this Lambda function to have a timeout of several minutes and I do not call any functions in 'context'
I've sunk several hours into trying to figure out how a Lambda function can end without any error message (from my code) or a timeout notice.
Is this a known behaviour? Does anyone know how I can find out what causes the function to suddenly stop with no output?
CodePudding user response:
What is the memory size configuration if the timeout is correct it might be the memory that is hampering the performance
CodePudding user response:
It possible when lambda abruptly exits in one of the code path. Something in lines of System.exit() in Java.
In JS, the lambda are run on loop to consume the event. If your fish function closes the lambda environment by maybe calling end of runtime / closing the socket on which the response is supposed to be sent. Lambda will finish there itself without sending response or timeout.
req.on('socket', function (socket) { socket.unref() })
