Has anyone else encountered unexpected timeouts with AWS Lambda functions? I have a function that has run smoothly for over three years, but recently it started timing out about 50% of the time, even though the execution typically takes under 300ms with a timeout setting of 30 seconds. This function simply saves a small entry to DynamoDB, so I'm puzzled as to why it suddenly has these issues. Any insights or similar experiences?
4 Answers
Without some instrumentation in place, it can be hard to diagnose what's going wrong. If you can access the source code, consider adding some basic logging for key actions—like starting up, connecting to DynamoDB, saving records, and completing the invocation. If your Lambda is pausing before it connects, there has to be something happening that's causing the delay.
It sounds like you might be dealing with a DNS or network timeout. Have you tried increasing the timeout limit to something like 10 minutes? If you find that it consistently times out after a minute, that's a clue to look into network issues.
Sounds like it might be time for some DEBUG logging! Adding logs can really help pinpoint where the process is stalling.
If your function has been unchanged for a while, it might be worth updating it. Sometimes making small adjustments can resolve these types of issues.

When it times out, it actually waits until the Lambda's timeout limit is reached, whether that's 30 seconds, 60 seconds, or longer. From my logging, it sometimes hangs just before or after the DynamoDB call, which adds to the confusion. It’s just sending data to DynamoDB and returning, so I'm not sure what else could be causing the hang.