Trying Out a 30-Minute Timeout for AWS Lambda Event Functions with Asynchronous Invocation and Step Functions

Trying Out a 30-Minute Timeout for AWS Lambda Event Functions with Asynchronous Invocation and Step Functions

I set a 1,800-second timeout on an AWS Lambda on-demand Event Function and ran it via asynchronous invocation and Step Functions Standard. Both ran past 15 minutes, and a function running the full time was cut off at 1,800 seconds.
2026.11.20

This page has been translated by machine translation. View original

Introduction

On November 19, 2026, there was an update that allows the timeout of AWS Lambda Event Functions (traditional Lambda) to be set up to 30 minutes.

https://aws.amazon.com/jp/about-aws/whats-new/2026/11/aws-lambda-30-minute-ondemand-event-functions/

This article introduces the results of creating functions with Timeout set to 1,800 seconds and invoking them both through asynchronous invocation and Step Functions Standard.

Test Environment

The test environment is as follows.

  • Region: ap-northeast-1
  • Runtime: Python 3.13
  • Architecture: arm64
  • Memory: 128 MB
  • Timeout: 1800 seconds
  • AWS CLI: 2.41.2

There are three functions. Every function outputs the current time every 10 seconds.

import os, time
from datetime import datetime, timezone

def now():
    return datetime.now(timezone.utc).isoformat(timespec="seconds")

def handler(event, context):
    run = int(os.environ["RUN_SECONDS"])  # 0 = keeps running until the limit
    start = time.monotonic()
    print("start", now(), "run_seconds", run)
    while True:
        elapsed = time.monotonic() - start
        if run and elapsed >= run:
            break
        print("tick", now(), int(elapsed))
        time.sleep(10)
    print("end", now())
    return {"finished": now()}
Function name RUN_SECONDS Invocation method
timeout30-async-30min 1790 Asynchronous invocation
timeout30-async-limit 0 Asynchronous invocation
timeout30-sfn-target 1790 Step Functions Standard

What I tested were on-demand synchronous invocation and asynchronous invocation. The conditions for using event source mappings (ESM) and Lambda Managed Instances are described in the official blog.

https://aws.amazon.com/blogs/compute/announcing-30-minute-timeout-for-on-demand-aws-lambda-event-functions/

Timeout Configuration

CloudFormation

Save a template that specifies 1800 for the Timeout of AWS::Lambda::Function as template.yaml, and create the stack.

aws cloudformation create-stack --stack-name timeout30-verify --template-body file://template.yaml --capabilities CAPABILITY_IAM
template.yaml (excerpt for timeout30-async-30min)

From the template used in the test, I kept only the resources needed for timeout30-async-30min (execution role, log group, function, EventInvokeConfig).

AWSTemplateFormatVersion: '2010-09-09'

Parameters:
  Runtime:
    Type: String
    Default: python3.13

Resources:
  FunctionRole:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Version: '2012-10-17'
        Statement:
          - Effect: Allow
            Principal: { Service: lambda.amazonaws.com }
            Action: sts:AssumeRole
      ManagedPolicyArns:
        - arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole

  Async30minLogGroup:
    Type: AWS::Logs::LogGroup
    Properties:
      LogGroupName: /aws/lambda/timeout30-async-30min
      RetentionInDays: 1
  Async30min:
    Type: AWS::Lambda::Function
    DependsOn: Async30minLogGroup
    Properties:
      FunctionName: timeout30-async-30min
      Runtime: !Ref Runtime
      Architectures: [arm64]
      MemorySize: 128
      Timeout: 1800
      Handler: index.handler
      Role: !GetAtt FunctionRole.Arn
      Environment:
        Variables:
          RUN_SECONDS: '1790'
      Code:
        ZipFile: |
          import os, time
          from datetime import datetime, timezone

          def now():
              return datetime.now(timezone.utc).isoformat(timespec="seconds")

          def handler(event, context):
              run = int(os.environ["RUN_SECONDS"])  # 0 = 上限まで動き続ける
              start = time.monotonic()
              print("start", now(), "run_seconds", run)
              while True:
                  elapsed = time.monotonic() - start
                  if run and elapsed >= run:
                      break
                  print("tick", now(), int(elapsed))
                  time.sleep(10)
              print("end", now())
              return {"finished": now()}
  Async30minConfig:
    Type: AWS::Lambda::EventInvokeConfig
    Properties:
      FunctionName: !Ref Async30min
      Qualifier: $LATEST
      MaximumRetryAttempts: 0

Measurement Results

The times in the table are the values (UTC) that the functions output to CloudWatch Logs. Duration is the value from the REPORT line. The output at 900 seconds elapsed corresponds to the previous limit of 15 minutes.

Function name Start Output at 900 seconds elapsed Last output Duration Result
timeout30-async-30min 11/19 23:57:47 11/20 00:12:47 end (11/20 00:27:37) 1790044.22 ms Completed normally
timeout30-async-limit 11/19 23:57:47 11/20 00:12:47 tick 1790 (11/20 00:27:37) 1800000.00 ms Status: timeout
timeout30-sfn-target 11/19 23:57:48 11/20 00:12:48 end (11/20 00:27:38) 1790044.61 ms Completed normally

Asynchronous Invocation

When you run invoke with --invocation-type Event, 202 is returned without waiting for the function to complete.

aws lambda invoke --function-name timeout30-async-30min --invocation-type Event --cli-binary-format raw-in-base64-out --payload '{}' response.json
{
    "StatusCode": 202
}

timeout30-async-limit was also invoked with the same command, changing only the function name.

This is the log of timeout30-async-30min, which finishes in 1,790 seconds.

start 2026-11-19T23:57:47+00:00 run_seconds 1790
tick 2026-11-19T23:57:47+00:00 0
...
tick 2026-11-20T00:12:47+00:00 900
...
tick 2026-11-20T00:27:27+00:00 1780
end 2026-11-20T00:27:37+00:00
END RequestId: e56f4d7d-2580-41b6-895c-75a691a3e4a9
REPORT RequestId: e56f4d7d-2580-41b6-895c-75a691a3e4a9	Duration: 1790044.22 ms	Billed Duration: 1790128 ms	Memory Size: 128 MB	Max Memory Used: 31 MB	Init Duration: 83.77 ms

This is the log of timeout30-async-limit, which keeps running until the limit.

start 2026-11-19T23:57:47+00:00 run_seconds 0
tick 2026-11-19T23:57:47+00:00 0
...
tick 2026-11-20T00:12:47+00:00 900
...
tick 2026-11-20T00:27:37+00:00 1790
END RequestId: 75ca460e-a8b0-40bf-b6f9-204fac038f65
REPORT RequestId: 75ca460e-a8b0-40bf-b6f9-204fac038f65	Duration: 1800000.00 ms	Billed Duration: 1800089 ms	Memory Size: 128 MB	Max Memory Used: 31 MB	Init Duration: 88.81 ms	Status: timeout

For the Python 3.13 functions this time, the termination could be identified by Status: timeout at the end of the REPORT line. No Task timed out line was output.

Synchronous Invocation from Step Functions Standard

From a lambda:invoke task in Step Functions Standard, I synchronously invoked timeout30-sfn-target, which finishes in 1,790 seconds. The execution was started with the following command.

aws stepfunctions start-execution --state-machine-arn arn:aws:states:ap-northeast-1:123456789012:stateMachine:timeout30-sfn --name run-1 --input '{}'

This is the result obtained with describe-execution about 30 minutes later (times are in JST).

    "status": "SUCCEEDED",
    "startDate": "2026-11-20T08:57:47.712000+09:00",
    "stopDate": "2026-11-20T09:27:38.227000+09:00",
State machine definition (StateMachineRole and StateMachine)

The invoked function SfnTarget is the definition of Async30min in the template.yaml above with FunctionName changed to timeout30-sfn-target. SfnTarget has no EventInvokeConfig attached.

  StateMachineRole:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Version: '2012-10-17'
        Statement:
          - Effect: Allow
            Principal: { Service: states.amazonaws.com }
            Action: sts:AssumeRole
      Policies:
        - PolicyName: invoke-sfn-target
          PolicyDocument:
            Version: '2012-10-17'
            Statement:
              - Effect: Allow
                Action: lambda:InvokeFunction
                Resource: !GetAtt SfnTarget.Arn

  StateMachine:
    Type: AWS::StepFunctions::StateMachine
    Properties:
      StateMachineName: timeout30-sfn
      StateMachineType: STANDARD
      RoleArn: !GetAtt StateMachineRole.Arn
      DefinitionString: !Sub |
        {
          "StartAt": "InvokeLongFunction",
          "States": {
            "InvokeLongFunction": {
              "Type": "Task",
              "Resource": "arn:aws:states:::lambda:invoke",
              "Parameters": {
                "FunctionName": "${SfnTarget.Arn}",
                "Payload.$": "$"
              },
              "End": true
            }
          }
        }

With synchronous invocation, how long the caller can wait differs depending on the caller. Step Functions waits until the function returns, but API Gateway waits 29 seconds by default for REST APIs and a maximum of 30 seconds for HTTP APIs.

https://docs.aws.amazon.com/lambda/latest/dg/lambda-services.html

Summary

The Timeout of AWS Lambda on-demand Event Functions has been extended from the previous 15 minutes to 30 minutes.

If the Lambda timeout has been a problem for things like batch processing that occasionally runs a little over 15 minutes, please try this update.

As also noted in the official blog, with the extended timeout, exception handling on the client side becomes important for synchronous invocation. We recommend using asynchronous invocation whenever possible, and if synchronous invocation is necessary, doing it from a stable execution environment such as Step Functions.

Share this article

AWSのお困り事はクラスメソッドへ