The full answer
AWS Lambda has a maximum execution time limit of 15 minutes (900 seconds) per invocation. If your function needs more time to complete its tasks, here are different ways to extend or optimize the runtime to handle long-running workloads efficiently.
Increase Lambda Timeout Setting
The simplest way to increase runtime is by configuring the timeout value in the Lambda function settings. This can be done using:
- AWS Management Console: Navigate to the Lambda function → Configuration → General settings → Set Timeout (max 900 seconds).
- AWS CLI: Run the following command to update the function timeout:
aws lambda update-function-configuration --function-name myLambdaFunction --timeout 900 - Terraform or AWS CDK: Specify the timeout in the deployment configuration.
Break Down Processing with Step Functions
If the function execution exceeds 15 minutes, use AWS Step Functions to break the task into multiple Lambda executions. Step Functions allow:
- Chaining multiple Lambda functions in a state machine workflow.
- Handling error retries, parallel execution, and long-running tasks efficiently.
Use SQS or Event-Driven Chaining for Async Processing
Instead of keeping Lambda running for long durations:
- Send tasks to an SQS queue, where another Lambda function picks them up for processing.
- Use SNS for triggering multiple Lambda functions asynchronously, reducing the need for long execution time in a single function.
Optimize Code and Resource Usage
- Use larger memory allocation since Lambda allocates CPU power proportionally to memory (higher memory = faster execution).
- Streamline code execution by removing unnecessary loops, database queries, or API calls.
- Use Amazon S3 or DynamoDB as temporary storage for stateful operations instead of keeping data in memory.
Offload Long Processing to EC2, Fargate, or Batch
If the workload naturally takes longer than 15 minutes, consider moving the process to a more suitable service:
- Amazon EC2: Run compute-heavy tasks without time restrictions.
- AWS Fargate (Serverless Containers): Ideal for long-running, event-driven workloads.
- AWS Batch: Best suited for large-scale batch processing tasks.
Tecyfy Takeaway: While the 15-minute execution limit cannot be extended, you can optimize Lambda processing, use Step Functions for long workflows, leverage SQS for event-driven execution, and offload heavy workloads to EC2, Fargate, or Batch for better scalability.
Last updated 12 February 2025