---
title: How to Remediate Lambda Functions with Excessive Timeouts | Stratusphere™
description: Discover how to tackle excessive timeouts in AWS Lambda. Learn strategies to optimize your functions in Stratusphere™ FinOps and boost your cloud efficiency.
image: https://stratusgrid.com/hubfs/How%20to%20Remediate%20Lambda%20Functions%20with%20Excessive%20Timeouts%20in%20StratusphereTM.svg
---

# How to Remediate Lambda Functions with Excessive Timeouts in Stratusphere™ FinOps

Discover how to tackle excessive timeouts in AWS Lambda. Learn strategies to optimize your functions in Stratusphere™ FinOps and boost your cloud efficiency.

[ Stratusphere's AWStronaut ](https://stratusgrid.com/knowledge-base/author/stratuspheres-awstronaute)

 Mar 8, 2024

#### Content Outline

- [Lambda Function Timeout Period](https://stratusgrid.com/knowledge-base/how-to-remediate-lambda-functions-with-excessive-timeouts#Lambda-Function-Timeout-Period)
- [Identify Excessive Timeouts in Lambda](https://stratusgrid.com/knowledge-base/how-to-remediate-lambda-functions-with-excessive-timeouts#Identify-Excessive-Timeouts-in-Lambda)
- [Risks & Other Considerations](https://stratusgrid.com/knowledge-base/how-to-remediate-lambda-functions-with-excessive-timeouts#Risks-Other-Considerations)
- [Remediation](https://stratusgrid.com/knowledge-base/how-to-remediate-lambda-functions-with-excessive-timeouts#Remediation)
- [Take Action to Optimize Your Lambda Functions Now!](https://stratusgrid.com/knowledge-base/how-to-remediate-lambda-functions-with-excessive-timeouts#Take-Action-to-Optimize)

### Need additional support?

### Subscribe

![How to Remediate Lambda Functions with Excessive Timeouts in Stratusphere™ FinOps](https://stratusgrid.com/hubfs/How%20to%20Remediate%20Lambda%20Functions%20with%20Excessive%20Timeouts%20in%20StratusphereTM.svg)

How to Remediate Lambda Functions with Excessive Timeouts | Stratusphere™

9:09

[AWS Lambda](https://aws.amazon.com/lambda/) is a managed service that enables you to deploy application code. You can write function code in many different programming languages, such as JavaScript, Python, Rust, and more.

One of the major benefits of running your business logic in AWS Lambda functions is that you’re billed for usage down to the millisecond level of granularity. Lambda also handles scaling for you automatically by running [parallel executions](https://docs.aws.amazon.com/lambda/latest/dg/lambda-concurrency.html) of your function code.

AWS Lambda functions have a service-imposed [maximum execution time of 15 minutes](https://aws.amazon.com/lambda/faqs/#:~:text=AWS%20Lambda%20allows%20you%20to,partition%20such%20as%20a%20shard.). In some application architectures, a Lambda function might be expected to execute for only a few milliseconds, or seconds. When Lambda functions are invoked, the request can be synchronous or asynchronous.

Synchronous invocations return a result immediately, whereas asynchronous functions run in the background without returning output to the caller.

For example, a Lambda function might retrieve data from a database and send it back to the caller. Another practical example would be a user registering an account for a SaaS service. A Lambda function might create a new user record in a storage mechanism such as [Amazon DynamoDB](https://aws.amazon.com/dynamodb/). For CPU-intensive data processing tasks, such as converting media file formats, a Lambda function could execute asynchronously, for several minutes.

## Lambda Function Timeout Period

Each Lambda function can be configured with [its own timeout threshold](https://docs.aws.amazon.com/lambda/latest/dg/configuration-function-common.html), in seconds. The default configuration is set for 3 seconds. If your function code exceeds this execution time, then the Lambda service will kill the function execution.

Although having a practical timeout threshold is important for cost control and predictable performance, premature termination of functions can also cause unpredictable application behavior. It’s best to configure your timeout for a reasonable value that’s slightly longer than your function’s expected execution time.

Here are some common scenarios where Lambda function timeouts could occur.

- Function code generally requires a longer timeout threshold
- Infinite loop bug in function code
- External service dependency takes longer than expected to respond

### Lambda Timeout Retries

When a Lambda function is invoked asynchronously and fails execution due to a timeout, the function is [retried up to 2 times](https://docs.aws.amazon.com/lambda/latest/dg/invocation-retries.html). Each time your Lambda function is retried, you will incur the cost of the function’s execution duration.

This can increase your cost for AWS Lambda compute time and invocation requests significantly, especially if your function is being invoked and retried frequently, and if you have a long timeout threshold configured. You can [modify the default Lambda retry behavior](https://docs.aws.amazon.com/lambda/latest/dg/invocation-async.html) to retry once or not at all.

### Specifying the Correct Timeout Threshold

When you’re deploying AWS Lambda functions, you can start with a higher timeout value, and progressively reduce it once you identify how long your function takes to execute, on average.

AWS Lambda automatically [emits metrics to the Amazon CloudWatch service](https://docs.aws.amazon.com/lambda/latest/dg/monitoring-metrics.html) that help you understand your function’s behavior. Keep an eye on the **Duration** metric to see how long your function takes to execute, and use this data to guide your timeout threshold.

## Identify Excessive Timeouts in Lambda

[Stratusphere™ FinOps](https://stratusphere.app/) is a Software-as-a-Service (SaaS) platform from [StratusGrid](https://stratusgrid.com/) that enables you to identify excessive timeouts in AWS Lambda functions across your entire organization.

According to the [documentation for AWS Trusted Advisor](https://docs.aws.amazon.com/awssupport/latest/user/cost-optimization-checks.html) – one of Stratusphere™ FinOps’s data sources – excessive timeouts are flagged when “*> 10% of invocations end in an error due to a timeout on any given day within the last 7 days*.” For example, if a function is invoked 1,000 times in a day, and 100 of those invocations result in the configured timeout threshold being exceeded, then this alert will be triggered.

In the Stratusphere™ FinOps web interface, navigate to the **Findings** section. Select the **Service** filter drop-down box and choose **AWS Lambda**. Select the **Levels of Effort** filter and select **High**. Stratusphere™ FinOps classifies the **Level of Effort** required for remediation as **High**, due to the potential for code debugging and external service investigation that may be required.

![Stratuspheres Findings Filters](https://stratusgrid.com/hs-fs/hubfs/Stratuspheres%20Findings%20Filters.webp?width=624&height=120&name=Stratuspheres%20Findings%20Filters.webp)

In the list below, you will see the AWS Lambda functions that are candidates for remediation due to excessive timeouts. Each of the AWS Lambda functions has a unique Amazon Resource Names (ARN), under the **Resource ID** column. This shows you which AWS account and region the function belongs to, so that you can locate it for remediation.

![Stratuspheres Findings Dashboard](https://stratusgrid.com/hs-fs/hubfs/Stratuspheres%20Findings%20Dashboard-3.webp?width=624&height=158&name=Stratuspheres%20Findings%20Dashboard-3.webp)

## Risks & Other Considerations

Before you apply a remediation technique for your AWS Lambda functions, you should consider the risks below.

- **Risk**: Increasing the Lambda function timeout threshold can increase cloud costs 
    - **Consideration**: Arbitrarily increasing your Lambda function timeout, without understanding what is causing it, can increase your AWS cloud spend. Make sure that you thoroughly test your code and understand the approximate, reasonable execution time. If the code is not executing within that threshold, you may want to add debugging messages to help identify what is causing performance slowdowns, or try increasing the memory allocation to the function.

## Remediation

Depending on the reason for the excessive timeouts in your AWS Lambda function, there may be a different approach to resolving it.

- Increase your Lambda function timeout threshold
- Investigate and resolve external service, and add monitoring
- Fix infinite loop in Lambda function code

Let’s explore each of these remediations in more depth, in the sections below.

### Increase Lambda Function Timeout

If your code takes longer to execute than the currently configured Lambda function timeout threshold, then you can simply increase the threshold to accommodate the estimated execution time. To update the Lambda function’s timeout threshold, follow these steps.

1. Login to the **AWS Management Console**
2. Select the **AWS Region** where your Lambda function exists
3. Navigate to the **AWS Lambda** service
4. Select your function from the **Functions** list
5. Select the **Configuration** tab from the function details
6. Select the **General Configuration** option
7. Click the **Edit** button
8. Specify a new value for the **Timeout** section
9. Click the **Save** button

![Stratuspheres AWS Lambda Timeout Settings](https://stratusgrid.com/hs-fs/hubfs/Stratuspheres%20AWS%20Lambda%20Timeout%20Settings.webp?width=439&height=161&name=Stratuspheres%20AWS%20Lambda%20Timeout%20Settings.webp)

This updated configuration should give your Lambda function code adequate time to execute. Feel free to repeat these steps to adjust the timeout period according to your requirements.

### Fix External Service Dependency

If you have an external service that your Lambda function code is dependent on, you will want to ensure that this service is healthy and responsive. Examples of service dependencies could include a REST API developed by an internal team, an external SaaS REST API, or a database service (eg. MySQL, Postgres).

StratusGrid recommends implementing observability tools, such as [Amazon CloudWatch](https://aws.amazon.com/cloudwatch/) or [Datadog](https://datadog.com/), to ensure that your services are responding with the expected results, and in a timely manner.

### Fix Infinite Loop Bug

Considering that AWS Lambda simply executes the code that you hand off to it, it’s possible for your code to cause an unexpected infinite loop. For example, consider the contrived scenario in the function code in the screenshot below. This code will never return a result to the Lambda runtime, because it is caught in an infinite “while” loop.

To fix this, we need to specify a condition to break out of the loop, so the rest of the Lambda handler function can execute. In Python, we can simply specify the **break** statement to break execution out of the loop and continue on. Alternatively, we could simply eliminate the loop from the function code entirely, and find another method of accomplishing our code’s objective.

![Fix Infinite Loop Bug](https://stratusgrid.com/hs-fs/hubfs/Fix%20Infinite%20Loop%20Bug.webp?width=495&height=309&name=Fix%20Infinite%20Loop%20Bug.webp)

## Take Action to Optimize Your Lambda Functions Now!

Frequent timeouts of AWS Lambda functions can drive up your cloud spend unnecessarily, and create instability in your business applications. 

Using [Stratusphere™ FinOps](https://stratusphere.app/) from StratusGrid, you can easily identify Lambda functions that are experiencing high rates of timeouts, and flag them for remediation. Once these remediation opportunities have been identified, your software development teams can take the necessary steps to remediate each function, according to its unique requirements.

If you're facing challenges with Lambda function timeouts or simply want to ensure your AWS Lambda functions are optimized for performance and cost-efficiency, we're here to help. [Contact us now](https://stratusgrid.com/book-a-consultation?hsLang=en) to take the first step towards optimized Lambda function performance.

Check out these resources for more information about AWS Lambda functions.

- [AWS Lambda Developer Guide](https://docs.aws.amazon.com/lambda/latest/dg/welcome.html)
- [Working with AWS Lambda function metrics](https://docs.aws.amazon.com/lambda/latest/dg/monitoring-metrics.html)
- [AWS Lambda Quotas ](https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-limits.html)

### See Stratusphere™ FinOps in Action Here:

 

BONUS: Download Your FinOps Guide to Effective Cloud Cost Optimization Here ⤵️

[![FinOps-Guide-Downloadable (2)](https://stratusgrid.com/hs-fs/hubfs/FinOps-Guide-Downloadable%20(2).webp?width=1307&height=448&name=FinOps-Guide-Downloadable%20(2).webp)](https://stratusgrid.com/free-finops-101-guide)

## Similar posts

<https://stratusgrid.com/knowledge-base/how-to-remediate-amazon-rds-idle-instances-stratusphere>

### [How to Remediate Amazon RDS Idle Instances with Stratusphere™ FinOps](https://stratusgrid.com/knowledge-base/how-to-remediate-amazon-rds-idle-instances-stratusphere)

Learn to reduce AWS costs with Stratusphere™ FinOps by efficiently remediating idle Amazon RDS instances, plus strategies to optimize your RDS...

 Stratusphere's AWStronaut  Mar 7, 2024

<https://stratusgrid.com/knowledge-base/remediate-over-provisioned-aws-lambda-functions-stratusphere>

### [How to Remediate Over-provisioned AWS Lambda Functions with Stratusphere™ FinOps](https://stratusgrid.com/knowledge-base/remediate-over-provisioned-aws-lambda-functions-stratusphere)

Optimize your AWS Lambda functions by uncovering over-provisioning with Stratusphere™ FinOps by StratusGrid. Ensure cost efficiency and performance...

 Stratusphere's AWStronaut  Mar 8, 2024

<https://stratusgrid.com/knowledge-base/how-to-remediate-underutilized-amazon-ebs-volumes>

### [How to Remediate Underutilized Amazon EBS Volumes in Stratusphere™](https://stratusgrid.com/knowledge-base/how-to-remediate-underutilized-amazon-ebs-volumes)

Learn how to remediate underutilized AWS EBS volumes with Stratusphere™. Discover actionable insights and strategies to optimize your cloud storage!

 Stratusphere's AWStronaut  Mar 12, 2024

```json
{
  "@context" : "https://schema.org",
  "@type" : "BlogPosting",
  "author" : {
    "@type" : "Person",
    "name" : "Stratusphere's AWStronaut",
    "url" : "https://stratusgrid.com/knowledge-base/author/stratuspheres-awstronaute"
  },
  "dateModified" : "2024-09-20T15:06:24.987Z",
  "datePublished" : "2024-03-08T01:40:04.000Z",
  "headline" : "How to Remediate Lambda Functions with Excessive Timeouts | Stratusphere™",
  "image" : [ "https://stratusgrid.com/hubfs/How%20to%20Remediate%20Lambda%20Functions%20with%20Excessive%20Timeouts%20in%20StratusphereTM.svg" ],
  "mainEntityOfPage" : {
    "@id" : "https://stratusgrid.com/knowledge-base/how-to-remediate-lambda-functions-with-excessive-timeouts",
    "@type" : "WebPage"
  },
  "publisher" : {
    "@type" : "Organization",
    "logo" : {
      "@type" : "ImageObject",
      "url" : "https://stratusgrid.com/hubfs/Vertical%20Black.png"
    },
    "name" : "StratusGrid"
  }
}
```

```json
{
  "@context" : "https://schema.org",
  "@type" : "VideoObject",
  "contentUrl" : "https://9312960.fs1.hubspotusercontent-na1.net/hubfs/9312960/Demo%20PE%20new%20logo.mp4",
  "dateModified" : "2023-10-11T00:04:47.088Z",
  "duration" : "PT3M6S",
  "height" : 2160,
  "name" : "Demo PE new logo",
  "thumbnailUrl" : "https://api-na1.hubapi.com/filemanager/api/v3/files/thumbnail-redirect/139601068952?portalId=9312960&size=medium",
  "uploadDate" : "2023-10-11T00:04:26.556Z",
  "width" : 3840
}
```

```json
{
  "@context" : "https://schema.org/",
  "@type" : "Product",
  "aggregateRating" : {
    "@type" : "AggregateRating",
    "bestRating" : "5",
    "ratingCount" : "1",
    "ratingValue" : "5",
    "reviewCount" : "1",
    "worstRating" : "0"
  },
  "brand" : {
    "@type" : "Brand",
    "name" : "StratusGrid"
  },
  "description" : "StratusGrid, a premier AWS Consulting Partner, specializes in AWS cloud migration, modernization, stabilization, and cloud cost optimization services.",
  "image" : "https://stratusgrid.com/",
  "name" : "StratusGrid",
  "review" : {
    "@type" : "Review",
    "author" : {
      "@type" : "Person",
      "name" : "G2"
    },
    "datePublished" : "2024-01-21",
    "name" : "G2 User",
    "publisher" : {
      "@type" : "Organization",
      "name" : "G2"
    },
    "reviewBody" : "Great Customer Service and Extremely Knowledgable Team",
    "reviewRating" : {
      "@type" : "Rating",
      "bestRating" : "5",
      "ratingValue" : "5",
      "worstRating" : "0"
    }
  }
}
```