I have a simple Laravel app using AWS Lambda functions. I am trying to debug why lambda times out sometimes, so I am logging one of the HTTP request parameters in the controller. But the issue is that the logs don't get recorded to CloudWatch when lambda times out. Why?
I log like this:
class ExchangeController extends Controller {
function balance(Request $request) {
Log::info("[ExchangeController] Start: " . $request->exchange . ", " . $_ENV['AWS_REQUEST_ID']);
$request->process();
Log::info("[ExchangeController] OK ");
...
Here you can see example of "Task timed out" log, as you can see there is no sign of my Log::info() output:
but in the case of non timed out function, my logs work just fine:


I'm not a Laravel coder, but in my experience with other languages, when a Lambda function times out, it is HARD-STOPPED. Execution flow seems to be aborted entirely - this includes any kind of last-gasp error handling/reporting or context-unraveling code that you might expect to run after a normal error. It's like someone pulled the plug out of the wall.
If you want to log the input, you need to log the input immediately on entry into the handler, and not as part of anything that is promised to complete later, because in the event of a timeout, later may not come.