Member-only story
Posting AWS lambda Timeout to external logging system like Sentry.
Aws lambda is a serverless technology which helps us to write program without worrying about infrastructure.
it get called and execute the code inside the handler function. by default max execution time for a lambda is defined as 300 second. which is 5 minute. and we can defined the timeout as well.
So when lambda is executing there are cases it gets timed out, once it is timed out , lambda execution is stopped or terminated. AWS logged time out to cloudWatch. But there is no way to log that info to external logging system. if we want to log this info to sentry or some other system, how we can do that.
We are going to discuss about that, the simplest approach, Create a timer in your lambda which get executed 1–2 second before your actual lambda timeout. and capture all diagnostic info in that timer and post to external system. For example i am having a lambda which has timeout of 30 second. i will increase the timeout to 31 or 32 second and will create a timer which will execute on 30th second. so if our lambda is running till 30th second, it means it is timed out as per previous configuration.
In Node js , we have a function getRemainingTimeInMillis() which give us remaining time for lambda execution, we use this function to get the lambda timed out and set the timer.