Configure Lambda function timeout - Amazon Lambda
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Configure Lambda function timeout

Lambda runs your code for a set amount of time before timing out. Timeout is the maximum amount of time in seconds that a Lambda function can run. The default value for this setting is 3 seconds, but you can adjust this in increments of 1 second up to a maximum value of 900 seconds (15 minutes).

This page describes how and when to update the timeout setting for a Lambda function.

Determining the appropriate timeout value for a Lambda function

If the timeout value is close to the average duration of a function, there is a higher risk that the function will time out unexpectedly. The duration of a function can vary based on the amount of data transfer and processing, and the latency of any services the function interacts with. Some common causes of timeout include:

  • Downloads from Amazon Simple Storage Service (Amazon S3) are larger or take longer than average.

  • A function makes a request to another service, which takes longer to respond.

  • The parameters provided to a function require more computational complexity in the function, which causes the invocation to take longer.

When testing your application, ensure that your tests accurately reflect the size and quantity of data and realistic parameter values. Tests often use small samples for convenience, but you should use datasets at the upper bounds of what is reasonably expected for your workload.

Configuring timeout (console)

You can configure function timeout in the Lambda console.

To modify the timeout for a function
  1. Open the Functions page of the Lambda console.

  2. Choose a function.

  3. Choose the Configuration tab and then choose General configuration.

    
                        The Configuration tab in the Lambda console.
  4. Under General configuration, choose Edit.

  5. For Timeout, set a value between 1 and 900 seconds (15 minutes).

  6. Choose Save.

Configuring timeout (Amazon CLI)

You can use the update-function-configuration command to configure the timeout value, in seconds. The following example command increases the function timeout to 120 seconds (2 minutes).

aws lambda update-function-configuration \ --function-name my-function \ --timeout 120

Configuring timeout (Amazon SAM)

You can use the Amazon Serverless Application Model to configure the timeout value for your function. Update the Timeout property in your template.yaml file and then run sam deploy.

Example template.yaml
AWSTemplateFormatVersion: '2010-09-09' Transform: AWS::Serverless-2016-10-31 Description: An AWS Serverless Application Model template describing your function. Resources: my-function: Type: AWS::Serverless::Function Properties: CodeUri: . Description: '' MemorySize: 128 Timeout: 120 # Other function properties...