Skip to content

How to Fix AWS Lambda Function Timeout Error

DodaTech Updated 2026-06-24 2 min read

In this tutorial, you'll learn about How to Fix AWS Lambda Function Timeout Error. We cover key concepts, practical examples, and best practices to help you understand and apply this topic effectively.

Your Lambda function returns Task timed out after 3.00 seconds — the execution duration exceeds the configured timeout.

Step-by-Step Fix

1. Increase the timeout

aws lambda update-function-configuration --function-name my-function --timeout 30

2. Check current configuration

aws lambda get-function-configuration --function-name my-function --query 'Timeout'

Expected output:

30

3. Optimize the Lambda code

import json

def lambda_handler(event, context):
    data = event.get("payload", {})
    result = process_data(data)
    return {"statusCode": 200, "body": json.dumps(result)}

def process_data(data):
    return {"processed": True, "input": data}

4. Increase memory (also increases CPU)

aws lambda update-function-configuration --function-name my-function --memory-size 1024

5. Configure reserved concurrency

aws lambda put-function-concurrency --function-name my-function --reserved-concurrent-executions 10

6. Use async invocation for long tasks

aws lambda invoke --function-name my-function --invocation-type Event --payload file://input.json output.txt

7. Check CloudWatch logs

aws logs describe-log-streams --log-group-name /aws/lambda/my-function --max-items 5

Common Mistakes

Mistake Fix
Timeout too low for the workload Increase timeout to 30s or higher
Function makes slow network calls Use connection pooling or async HTTP
Cold start delay Increase memory or use Provisioned Concurrency
Infinite loop in code Add a loop counter or timeout in code
Database connection timeout Use RDS Proxy or connection pooling

Prevention

  • Set timeout based on the function's actual runtime plus 20% buffer.
  • Use CloudWatch Lambda Insights for performance monitoring.
  • Implement idempotent retry logic.
  • Use Step Functions for workflows exceeding 15 minutes.

Common Mistakes with lambda timeout

  1. Misunderstanding that String is [Char] with poor performance for large text operations
  2. Using foldl instead of foldl' causing stack overflow on large lists
  3. Forgetting deriving (Show, Eq) on custom data types needed for debugging

These mistakes appear frequently in real-world AWS code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

What is the maximum Lambda timeout?

The maximum timeout for AWS Lambda is 900 seconds (15 minutes). For longer tasks, use AWS Step Functions or Amazon ECS. |||How does memory affect Lambda timeout? Higher memory allocation also increases CPU allocation, making functions complete faster. Start with 1024 MB and adjust based on CloudWatch metrics. |||Why does my Lambda time out only sometimes? Intermittent timeouts are often caused by cold starts, database Connection Pool exhaustion, or external API latency. Check CloudWatch Logs for patterns.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro