I Tried Setting Up an Event Source Mapping with AWS Lambda and SQS FIFO with a Batch Size of 10,000

I Tried Setting Up an Event Source Mapping with AWS Lambda and SQS FIFO with a Batch Size of 10,000

I set a batch size of 10,000 on an AWS Lambda SQS FIFO event source mapping in provisioned mode and processed 10,000 messages across 1,000 groups. It took 2 invocations versus 1,000 with BatchSize 10, and each group's 10 messages arrived in sequence order.
2026.11.23

This page has been translated by machine translation. View original

Introduction

On November 20, 2026, the Amazon SQS FIFO queue event source mapping (ESM) for AWS Lambda began supporting a batch size of up to 10,000.

https://aws.amazon.com/about-aws/whats-new/2026/11/aws-lambda-10K-batch-size-SQSFIFO/

This article presents the results of processing 10,000 messages with a provisioned mode ESM while preserving the order within each message group.

Test Environment

  • Region: Tokyo (ap-northeast-1)
  • AWS CLI: 2.42.1
  • Lambda function: Python 3.13, memory 512 MB, timeout 60 seconds
  • Execution role: AWSLambdaSQSQueueExecutionRole attached
  • SQS FIFO queues: devio-fifo-batch-a.fifo (for the ESM with BatchSize 10000), devio-fifo-batch-b.fifo (for the ESM with BatchSize 10)
  • Queue VisibilityTimeout: 900 seconds
  • Deduplication: MessageDeduplicationId specified
  • Messages: 10,000 per queue (1,000 groups × 10 messages), 19-byte body
  • Number of provisioned mode pollers: MinimumPollers 2 / MaximumPollers 2

Test Preparation

Lambda Function

We prepare a function that outputs, for each invocation, a single log line containing the number of records, the number of groups, the sequence numbers for each group, and the size of the event.

handler.py
import json
import time

# Receive an SQS FIFO ESM batch and output one summary line per invocation to CloudWatch Logs.
# Body: {"g": "<group ID>", "s": <sequence number within the group>}


def handler(event, context):
    start_ms = int(time.time() * 1000)
    records = event["Records"]
    groups = {}
    for r in records:
        body = json.loads(r["body"])
        groups.setdefault(body["g"], []).append(body["s"])

    # Whether the sequence number increases by 1 for each group within the batch
    in_batch_violations = 0
    for seqs in groups.values():
        for a, b in zip(seqs, seqs[1:]):
            if b != a + 1:
                in_batch_violations += 1

    summary = {
        "request_id": context.aws_request_id,
        "start_ms": start_ms,
        "queue": records[0]["eventSourceARN"].split(":")[-1] if records else None,
        "records": len(records),
        "groups": len(groups),
        "max_per_group": max((len(v) for v in groups.values()), default=0),
        "in_batch_violations": in_batch_violations,
        "event_json_bytes": len(json.dumps(event)),
        "group_seqs": groups,
    }
    print("BATCH " + json.dumps(summary, separators=(",", ":")))
    return {}

Sending Messages

A single batch can contain at most 10 messages per message group, so to make batches larger you increase the number of groups. We send 10,000 messages as 1,000 groups of 10 messages each, submitting them sequentially with one send-message-batch call per group.

Sending is completed before creating the ESM.

python3 gen-entries.py /tmp/devio-fifo-entries
bash send.sh https://sqs.ap-northeast-1.amazonaws.com/123456789012/devio-fifo-batch-a.fifo /tmp/devio-fifo-entries
calls: 1000
successful_messages: 10000
failed_messages: 0

We sent 10,000 messages to the queue for the BatchSize 10 ESM using the same procedure.

gen-entries.py and send.sh

gen-entries.py

#!/usr/bin/env python3
"""送信用エントリを作る。1 グループ = 1 ファイル = 1 回の send-message-batch(10 件)。

使い方: gen-entries.py <出力ディレクトリ> [グループ数=1000] [グループあたり件数=10]
"""
import json
import os
import sys

out = sys.argv[1]
n_groups = int(sys.argv[2]) if len(sys.argv) > 2 else 1000
per_group = int(sys.argv[3]) if len(sys.argv) > 3 else 10
os.makedirs(out, exist_ok=True)

for j in range(n_groups):
    gid = f"g{j:04d}"
    entries = [
        {
            "Id": str(i),
            "MessageBody": json.dumps({"g": gid, "s": i}, separators=(",", ":")),
            "MessageGroupId": gid,
            "MessageDeduplicationId": f"{gid}-{i}",
        }
        for i in range(per_group)
    ]
    with open(os.path.join(out, f"{gid}.json"), "w") as f:
        json.dump(entries, f)
print(f"generated {n_groups} files, {n_groups * per_group} messages")

send.sh

#!/usr/bin/env bash
# Usage: send.sh <queue URL> <entries directory>
# Send each file (1 group, 10 messages) in parallel with send-message-batch, and tally the successful and failed counts.
set -u
QUEUE_URL="$1"
DIR="$2"
OUT=$(mktemp)
ls "$DIR"/*.json | xargs -P 16 -I{} \
  aws sqs send-message-batch --queue-url "$QUEUE_URL" --entries file://{} \
  --query '[length(Successful || `[]`), length(Failed || `[]`)]' --output text >"$OUT" 2>&1
echo "calls: $(wc -l <"$OUT")"
awk '{s+=$1; f+=$2} END {print "successful_messages: " s; print "failed_messages: " f+0}' "$OUT"
grep -v -E '^[0-9]+\s+[0-9]+$' "$OUT" | head -5
rm -f "$OUT"

ESM Configuration

Creating a New ESM

To set the batch size larger than 10, the batching window must be 1 second or more. For FIFO queues, the batching window can only be configured in provisioned mode, so we specify the number of pollers (to enable provisioned mode), the batch size, and the batching window in a single command.

aws lambda create-event-source-mapping \
  --function-name devio-fifo-batch-fn \
  --event-source-arn arn:aws:sqs:ap-northeast-1:123456789012:devio-fifo-batch-a.fifo \
  --batch-size 10000 \
  --maximum-batching-window-in-seconds 300 \
  --provisioned-poller-config MinimumPollers=2,MaximumPollers=2
{
    "UUID": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111",
    "BatchSize": 10000,
    "MaximumBatchingWindowInSeconds": 300,
    "EventSourceArn": "arn:aws:sqs:ap-northeast-1:123456789012:devio-fifo-batch-a.fifo",
    "FunctionArn": "arn:aws:lambda:ap-northeast-1:123456789012:function:devio-fifo-batch-fn",
    "LastModified": "2026-11-22T00:27:50.579000+09:00",
    "State": "Creating",
    "StateTransitionReason": "USER_INITIATED",
    "FunctionResponseTypes": [],
    "EventSourceMappingArn": "arn:aws:lambda:ap-northeast-1:123456789012:event-source-mapping:a1b2c3d4-5678-90ab-cdef-EXAMPLE11111",
    "ProvisionedPollerConfig": {
        "MinimumPollers": 2,
        "MaximumPollers": 2
    }
}

The state was Creating 10 seconds after creation and Enabled after 72 seconds.

Updating an Existing ESM

After the default mode ESM created with BatchSize 10 finished processing 10,000 messages, we update this ESM. Switching to provisioned mode and changing the batch size and batching window are done together in a single update.

aws lambda update-event-source-mapping \
  --uuid a1b2c3d4-5678-90ab-cdef-EXAMPLE22222 \
  --batch-size 10000 \
  --maximum-batching-window-in-seconds 300 \
  --provisioned-poller-config MinimumPollers=2,MaximumPollers=2 \
  --query '{UUID:UUID,State:State,BatchSize:BatchSize,Window:MaximumBatchingWindowInSeconds,Pollers:ProvisionedPollerConfig,LastProcessingResult:LastProcessingResult}'
{
    "UUID": "a1b2c3d4-5678-90ab-cdef-EXAMPLE22222",
    "State": "Updating",
    "BatchSize": 10000,
    "Window": 300,
    "Pollers": {
        "MinimumPollers": 2,
        "MaximumPollers": 2
    },
    "LastProcessingResult": null
}

Processing Results

Number of Invocations and Records

We sent the same 10,000 messages to separate queues and processed them with an ESM with BatchSize 10000 and an ESM with BatchSize 10. Each value is the result of a single test run.

mode BatchSize Batching window Invocations Records per invocation Order violations within a group
provisioned mode 10000 300 seconds 2 5,000 (500 groups × 10 messages) 0
default mode 10 0 seconds 1,000 10 (1 group) 0

The number of records per invocation was 5,000, not the configured 10,000.

Payload Size

For the invocation that received 5,000 records, the event size measured with json.dumps inside the function was 4,795,013 bytes (about 4.8 MB), which fit within the 6 MB payload limit for synchronous invocation. That is about 959 bytes per record, roughly 50 times the 19-byte message body.

Time Until Processing Started

72 seconds after the ESM creation request, the number of in-flight messages in the queue was 10,000. With a batching window of 300 seconds, the first invocation occurred about 319 seconds after the creation request.

Log Aggregation and Order Within Groups

The Lambda function logs are retrieved with the following command and saved to batch-logs.json.

aws logs filter-log-events \
  --log-group-name /aws/lambda/devio-fifo-batch-fn \
  --filter-pattern BATCH \
  --query "events[].message" \
  --output json > batch-logs.json

The retrieved logs are aggregated with analyze.py.

analyze.py
#!/usr/bin/env python3
"""BATCH ログ(filter-log-events の JSON 配列)を集計する。

使い方: analyze.py <ログファイル> [キュー名の部分一致]
出力: 呼び出し回数、件数の分布、グループ内順序の検査結果。
"""
import json
import sys
from collections import Counter, defaultdict

path = sys.argv[1]
qfilter = sys.argv[2] if len(sys.argv) > 2 else ""
lines = open(path).read().split("\n")
start = next(i for i, l in enumerate(lines) if l == "[")
end = next(i for i in range(len(lines) - 1, -1, -1) if lines[i] == "]")
msgs = json.loads("\n".join(lines[start:end + 1]))
inv = []
for m in msgs:
    d = json.loads(m[m.index("BATCH ") + 6:])
    if qfilter in (d["queue"] or ""):
        inv.append(d)
inv.sort(key=lambda d: d["start_ms"])
print(f"invocations: {len(inv)}")
print(f"total_records: {sum(d['records'] for d in inv)}")
print(f"records_per_invocation: min={min(d['records'] for d in inv)} max={max(d['records'] for d in inv)}")
dist = Counter(d["records"] for d in inv)
if len(inv) <= 30:
    for d in inv:
        print(f"  start_ms={d['start_ms']} records={d['records']} groups={d['groups']} max_per_group={d['max_per_group']} in_batch_violations={d['in_batch_violations']} event_json_bytes={d['event_json_bytes']}")
else:
    print("records_distribution:", dict(sorted(dist.items())))
print(f"max_per_group_overall: {max(d['max_per_group'] for d in inv)}")
print(f"in_batch_violations_total: {sum(d['in_batch_violations'] for d in inv)}")
print(f"first_start_ms={inv[0]['start_ms']} last_start_ms={inv[-1]['start_ms']}")
# For each group, check whether the sequence numbers, ordered by invocation start, are ascending 0..n-1
seq_by_group = defaultdict(list)
for d in inv:
    for g, seqs in d["group_seqs"].items():
        seq_by_group[g].extend(seqs)
bad = [g for g, s in seq_by_group.items() if s != list(range(len(s)))]
dup = sum(len(s) - len(set(s)) for s in seq_by_group.values())
print(f"groups_seen: {len(seq_by_group)}")
print(f"messages_per_group: {dict(Counter(len(s) for s in seq_by_group.values()))}")
print(f"groups_out_of_order_or_missing: {len(bad)}")
print(f"duplicate_deliveries: {dup}")

Here are the results for the ESM with BatchSize 10000.

python3 analyze.py batch-logs.json devio-fifo-batch-a
invocations: 2
total_records: 10000
records_per_invocation: min=5000 max=5000
  start_ms=1795275189984 records=5000 groups=500 max_per_group=10 in_batch_violations=0 event_json_bytes=4795013
  start_ms=1795275190089 records=5000 groups=500 max_per_group=10 in_batch_violations=0 event_json_bytes=4795013
max_per_group_overall: 10
in_batch_violations_total: 0
first_start_ms=1795275189984 last_start_ms=1795275190089
groups_seen: 1000
messages_per_group: {10: 1000}
groups_out_of_order_or_missing: 0
duplicate_deliveries: 0

For all 1,000 groups, the 10 messages arrived together in a single invocation in ascending order from 0 to 9.

Summary

We were able to set BatchSize 10000 on a provisioned mode ESM for an SQS FIFO queue (batching window 300 seconds).

Previously, a batch held at most 10 messages, so processing 10,000 messages required 1,000 or more invocations, but in this measurement with BatchSize 10000, it was processed in 2 invocations (5,000 messages each).

If your processing that registers data from SQS into an RDBMS is an asynchronous implementation that does not require per-message transactions and can tolerate lag before the data is reflected, increasing the batch size can be expected to improve throughput. We recommend evaluating this update.

Share this article

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