DEV Community

Prabhakaran Jayaraman Masani
Prabhakaran Jayaraman Masani

Posted on Originally published at prabhakaranjm.medium.com

Thirty Minutes on Lambda: Running Long AI Agent Tasks Without Re-architecting

What the new 30-minute timeout for on-demand Lambda Event Functions changes for agent workloads, the settings that must move with it, and when to switch to durable functions instead

The problem: agents do not respect the 15-minute wall

For eight years, 15 minutes was one of the hard numbers you designed around on AWS Lambda. Most event-driven work fits easily inside it. Agentic work often does not. A single agent request can chain several model calls, wait on slow tools, read documents, retry when output fails validation and then write up a result. Add a large input or a busy model endpoint and the request drifts past 15 minutes.

The usual workarounds all add moving parts. You split the agent loop into AWS Step Functions states, move the job to an Amazon ECS task, or write your own checkpoint-and-re-enqueue logic on Amazon SQS. Each of these is a valid pattern, but it is a lot of machinery when the only real problem is that one invocation needs 20 minutes.

On 19 November 2026 AWS raised the limit. On-demand Lambda Event Functions can now run for up to 30 minutes (1,800 seconds) for synchronous, asynchronous and event source mapping (ESM) invocations. The AWS Compute Blog launch post names "agentic AI requests that chain model calls and tool invocations" as one of the workloads it is aimed at. This article covers what changed, the settings you have to change along with it, and how it fits with Lambda durable functions.

What actually changed

From the launch post and the Lambda Developer Guide:

  • On-demand Event Functions: synchronous, asynchronous and ESM invocations can all run for up to 30 minutes.
  • Lambda Managed Instances: synchronous invocations also go up to 30 minutes. Asynchronous and ESM invocations keep the 90-minute (5,400 second) limit introduced in September 2026.
  • Init phase limits are unchanged: 10 seconds on demand and 15 minutes on Lambda Managed Instances.
  • Durable functions: each invocation inside a durable execution can now run for up to 30 minutes. A durable execution started asynchronously can still span up to one year. Synchronous durable executions are capped at 30 minutes overall.
  • Exceptions: Amazon MQ and Amazon DocumentDB event source mappings stay at 14 minutes. So do Kafka mappings created before 19 November 2026 that do not use provisioned mode; to get the new limit you create a new mapping or turn on provisioned mode.
  • Availability and price: all commercial Regions for on-demand functions, at standard Lambda pricing.

Nothing else about the function changes. It keeps the same runtime, handler, execution role and VPC configuration, and the new value applies to invocations that start after you update it.

Architecture: a queue-driven agent worker

The pattern I find most natural for long agent tasks is a queue in front of a single Lambda function, with durable functions held back for jobs where a restart would be expensive.

Architecture diagram: SQS queue feeding a Lambda agent worker, with durable functions for expensive restarts

The queue soaks up bursts, the ESM controls how many agents run at once, and a dead-letter queue catches tasks that keep failing. Jobs that can safely be re-run from scratch go through the plain worker. Jobs where losing 20 minutes of model calls would hurt go to a durable function.

Hands-on: raising the timeout safely

1. Set the function timeout

The CLI change is one flag, as shown in the launch post:

aws lambda update-function-configuration \
  --function-name agent-worker \
  --timeout 1800 \
  --region eu-west-2
Enter fullscreen mode Exit fullscreen mode

In AWS SAM it is the Timeout property:

AgentWorker:
  Type: AWS::Serverless::Function
  Properties:
    FunctionName: agent-worker
    Runtime: python3.14
    Handler: app.handler
    Timeout: 1800
    MemorySize: 2048
Enter fullscreen mode Exit fullscreen mode

Anything above 1,800 seconds on an on-demand function is rejected with a validation error.

2. Make the SQS visibility timeout match

The SQS guidance does not change: set the queue's visibility timeout to at least six times the function timeout. For a 30-minute function that means at least 3 hours (10,800 seconds).

aws sqs set-queue-attributes \
  --queue-url https://sqs.eu-west-2.amazonaws.com/123456789012/agent-tasks \
  --attributes VisibilityTimeout=10800
Enter fullscreen mode Exit fullscreen mode

Lambda checks this when you create the event source mapping. It does not stop you from changing the queue or the function later and creating a mismatch, so I would put both values in the same IaC stack. Then create the mapping with partial batch failure reporting, so one failed task does not send the whole batch back to the queue:

aws lambda create-event-source-mapping \
  --function-name agent-worker \
  --event-source-arn arn:aws:sqs:eu-west-2:123456789012:agent-tasks \
  --batch-size 1 \
  --function-response-types ReportBatchItemFailures
Enter fullscreen mode Exit fullscreen mode

With a batch size of 1, each agent task gets the whole 30 minutes to itself. That is a design choice rather than a requirement.

3. Fix the client side of synchronous calls

If anything invokes the function synchronously, its read timeout has to be longer than the function timeout. The launch post calls out the AWS SDK read timeout in particular. In boto3 that is a botocore Config (illustrative values, not a recommendation):

# Illustrative: caller invoking a 30-minute function synchronously
import boto3
from botocore.config import Config

lambda_client = boto3.client(
    "lambda",
    config=Config(
        read_timeout=1900,          # longer than the 1800s function timeout
        tcp_keepalive=True,         # the launch post advises TCP keep-alive on long sync calls
        retries={"max_attempts": 0} # avoid the SDK silently re-running a 30-minute agent task
    ),
)

resp = lambda_client.invoke(
    FunctionName="agent-worker",
    Payload=b'{"task_id": "t-123"}',
)
Enter fullscreen mode Exit fullscreen mode

Also, if another AWS service calls your function synchronously, it applies its own timeout. Check that the caller can actually wait 30 minutes before you rely on the new limit. For anything user-facing, I would still return a task ID straight away and let the client poll.

4. Use durable functions when restarts are expensive

The launch post is clear about how the two features fit together. --timeout limits a single invocation. ExecutionTimeout in --durable-config limits the whole durable execution. Without checkpoints, a 25-minute run that fails at minute 22 starts again from zero. With durable functions, it resumes from the last completed step.

You can only turn on durable execution when you create a function:

aws lambda create-function \
  --function-name research-agent \
  --runtime python3.14 \
  --role arn:aws:iam::123456789012:role/research-agent-role \
  --handler app.lambda_handler \
  --zip-file fileb://function.zip \
  --timeout 1800 \
  --durable-config '{"ExecutionTimeout": 86400, "RetentionPeriodInDays": 14}'
Enter fullscreen mode Exit fullscreen mode

The handler below uses the decorators and context.step() API from the durable functions getting-started guide. The agent logic and Bedrock prompt are illustrative:

# Illustrative agent flow using the AWS Durable Execution SDK for Python
import boto3
from aws_durable_execution_sdk_python import DurableContext, durable_execution, durable_step

bedrock = boto3.client("bedrock-runtime")
MODEL_ID = "your-model-id"  # placeholder

def ask(prompt):
    resp = bedrock.converse(
        modelId=MODEL_ID,
        messages=[{"role": "user", "content": [{"text": prompt}]}],
    )
    return resp["output"]["message"]["content"][0]["text"]

@durable_step
def plan(step_context, question):
    return ask(f"Break this research question into sub-questions: {question}")

@durable_step
def research(step_context, sub_question):
    return ask(f"Answer concisely with sources: {sub_question}")

@durable_step
def synthesise(step_context, findings):
    return ask("Write a short report from these findings:\n" + "\n".join(findings))

@durable_execution
def lambda_handler(event, context: DurableContext):
    outline = context.step(plan(event["question"]))
    sub_questions = [q for q in outline.splitlines() if q.strip()][:5]
    findings = [context.step(research(q)) for q in sub_questions]
    return {"report": context.step(synthesise(findings))}
Enter fullscreen mode Exit fullscreen mode

Two durable-function rules matter here. You must invoke them with a qualified identifier (a version, an alias or $LATEST), and for deterministic replay the docs recommend a published version. Also, steps run at least once by default, so a step that fails before its checkpoint can run again.

aws lambda invoke \
  --function-name research-agent:1 \
  --invocation-type Event \
  --cli-binary-format raw-in-base64-out \
  --payload '{"question": "Compare serverless options for long-running agents"}' \
  response.json
Enter fullscreen mode Exit fullscreen mode

Trade-offs, cost and security notes

  • Concurrency doubles with duration. The launch post spells out the formula: concurrency equals requests per second multiplied by average duration. One request per second at 30 minutes each needs 1,800 concurrent executions. Check your account quota and use reserved concurrency so a backlog of agents cannot starve other functions.
  • Cost is still duration-based. Standard Lambda pricing applies, so an agent waiting on a slow model call is billed for that wait. Durable wait() operations pause without using compute, which suits human approval or long polling better than sleeping inside an invocation.
  • Idle connections drop. A NAT gateway drops idle connections after 350 seconds. Send keep-alives, and make sure RDS, ElastiCache and third-party API idle timeouts can cover the full run. For JVM functions, set a short DNS TTL.
  • Credentials can expire mid-run. If the function gets its own temporary credentials or OAuth tokens for tools, make sure they last for the whole invocation or refresh them in the background.
  • Duplicates get more expensive. Lambda does not guarantee exactly-once processing, and a longer run gives retries more room to overlap. Make side effects idempotent, for example with Powertools for AWS Lambda, or use the execution name as an idempotency key for durable executions.
  • Streams slow down. For Kinesis and DynamoDB Streams, longer invocations hold each shard for longer. Watch IteratorAge and raise the parallelisation factor if records start to back up.
  • It is not unlimited. If a task can run for hours, choose asynchronous durable functions, Step Functions Standard or Lambda Managed Instances on purpose. A function timeout set to the maximum should not be your only safety net.

Conclusion

The 30-minute timeout is a small number change with a real effect on design. Many agent workloads that used to need a workflow engine or a container just for the extra minutes can now stay as one Lambda function behind a queue. The work moves into the surrounding settings: SQS visibility timeouts, client read timeouts, concurrency, keep-alives, credential lifetimes and idempotency. My rule of thumb: if a restart is cheap, raise the timeout and harden those settings. If a restart is expensive, keep the 30-minute invocations and add durable checkpoints.

References

Top comments (0)