My wife and seed would agree that talking about AWS Lambdas are in my “big three” of things to not shut up about, along with fishing and professional wrestling.
Regardless, I do love them so (both the Lambdas and the fam bam).
As I’ve grown to use them more and more frequently for both work and play, I’ve honed in on how to improve performance as well as how to debug them when they decide to stop working as expected.
Here are a few of my favorite tips and tricks to quickly figure out what may be wrong with your Lambda:
1. Check the recent invocation logs
For all the ridicule that the AWS console receives, they still provide you with everything you need to figure out what the hell may be going wrong. It may be obvious, but checking the logs will usually reveal something, especially if the issue is caused by your code and not a configuration issue.
To check the logs, go to your Lambda, click on
Monitor and then
Logs to list
out recent invocations. Clicking the
LogStream link will get you more details.
2. Check the memory usage
Digging into the logs is great if you have a failure in your code that is dumping out an error, but if you’re maxing out your configured memory allotment, you will need to take a deeper look into the logs to see how much memory was consumed.
An easier approach is to list out the recent invocations (without drilling down into the logs) and you will see how much memory was allocated and how much was consumed. If you’re running out of memory your consumed memory will be the same as the configured memory, but also could be a megabyte or so more.
The values you want are
3. Check the execution time
Similar to memory usage, if your Lambda is running longer than the configured execution time, it’ll bomb out somewhat silently. By default an AWS Lambda has an execution time of three (3) seconds. This tends to be enough time if your code isn’t doing much and/or isn’t interfacing with external services.
I can’t even tell you how many times this has bit me and some of my peers. Hits especially hard when you’re adding logging to your function and you cry out “it’s not even getting to my code, what the actual eff?!”
Same place as before, but you’ll want to check