Timeout - Serverless Architectures with AWS Lambda

Timeout

You can designate the maximum amount of time a single function execution is allowed to complete before a timeout is returned. The maximum timeout for a Lambda function is 300 seconds at the time of this publication, which means a single invocation of a Lambda function cannot execute longer than 300 seconds. You should not always set the timeout for a Lambda function to the maximum. There are many cases where an application should fail fast. Because your Lambda function is billed based on execution time in 100-ms increments, avoiding lengthy timeouts for functions can prevent you from being billed while a function is simply waiting to timeout (perhaps an external dependency is unavailable, you’ve accidentally programmed an infinite loop, or another similar scenario).

Also, once execution completes or a timeout occurs for your Lambda function and a response is returned, all execution ceases. This includes any background processes, subprocesses, or asynchronous processes that your Lambda function might have spawned during execution. So you should not rely on background or asynchronous processes for critical activities. Your code should ensure those activities are completed prior to timeout or returning a response from your function.