We can all agree that troubleshooting AWS Lambda timeouts can be tricky, here are some things to try when troubleshooting.
The Lambda timeouts can be caused by not enough memory or processing power of the Lambda itself, or can be caused by other services.
The way to find out what is the reason for the timeout, is digging into the Lambda logs and checking the logs of the container that ended with timeout. If the logs show that the used memory is the same as allocated memory then it is a lack of memory issue. When this happens, usually the container freezes, just stops at whatever was doing and consequently ends with a timeout. The lack of memory issue could be caused simply because Lambda needs more memory, so increasing the memory size will fix it. But it is always worth exploring the reason behind. Like in this case, where the underlying framework caused a lack of memory issue.
But what if the memory usage is not the reason for the timeout? Again, digging into the Lambda logs should give us the answer. By adding proper logs, you can easily see at which stage the Lambda freezes. If you are calling a service that takes too long to respond or is not scalable enough, by looking at the logs you should be able to see that the Lambda execution stopped at that particular service call. Usually this kind of issue can happen when Lambda is under load, but the underlying service cannot scale at the speed that Lambda is scaling. If this is the case then fixing the issue with the service will fix the timeout as well.
If none of the above is the case and you are still experiencing a timeout, it could be that your Lambda function does not have enough processing power. Usually this is the case when Lambda does CPU intensive work. Lambda allocates CPU power proportional to the amount of memory provisioned. So the more memory is allocated, the more CPU power is allocated too. Even if the whole memory is not used, the function will gain more CPU power and thus will execute faster.
Hope this information will help with resolving your Lambda timeout issues.
Top comments (0)