The PutEvents API in EventBridge is designed to allow you to send multiple events in a single request, up to 10 events per call. This is a crucial optimization for reducing latency and operational overhead when publishing events from your applications.

Let’s see it in action. Imagine you have a microservice that processes customer orders. For each completed order, it needs to publish two distinct events: one for order fulfillment and another for inventory adjustment. Instead of making two separate PutEvents calls, we can batch them.

Here’s a conceptual Python example using boto3:

import boto3
import json
from datetime import datetime

events_client = boto3.client('events')

order_id = "ORD12345"
customer_id = "CUST987"
product_id = "PROD654"
quantity = 2
timestamp = datetime.utcnow().isoformat()

entry_1 = {
    'Source': 'com.mycompany.orders',
    'DetailType': 'OrderFulfilled',
    'EventBusName': 'default',
    'Time': datetime.utcnow(),
    'Detail': json.dumps({
        'orderId': order_id,
        'customerId': customer_id,
        'products': [{'productId': product_id, 'quantity': quantity}],
        'timestamp': timestamp
    })
}

entry_2 = {
    'Source': 'com.mycompany.inventory',
    'DetailType': 'InventoryAdjusted',
    'EventBusName': 'default',
    'Time': datetime.utcnow(),
    'Detail': json.dumps({
        'orderId': order_id,
        'productId': product_id,
        'adjustment': -quantity,
        'timestamp': timestamp
    })
}

response = events_client.put_events(
    Entries=[
        entry_1,
        entry_2
    ]
)

print(response)

In this example, entry_1 represents the order fulfillment event, and entry_2 represents the inventory adjustment. Both are packaged into a single PutEvents call. The Entries parameter is a list where each item is an Event object.

The core problem this solves is the overhead associated with individual API calls. Each PutEvents call incurs network latency, authentication, and authorization checks. When you need to publish many events, especially in rapid succession, batching them into a single PutEvents request significantly reduces this overhead. EventBridge can process up to 10 events per PutEvents call, and each call is billed as a single API request. This means if you send 10 events in one batch, you’re charged for one PutEvents API call, not ten.

Internally, EventBridge receives this batch and processes each event within it. It then routes each event independently based on its Source, DetailType, and EventBusName to any configured rules. The EventBusName is important for directing events to specific buses, though default is commonly used. The Source typically identifies the AWS service or application that generated the event, and DetailType provides a more specific classification of the event within that source. The Detail field is a JSON string containing the actual event payload.

The maximum number of events you can send in a single PutEvents request is 10. If you have more than 10 events to send, you must split them into multiple PutEvents calls. The total size of the batch, including metadata and the JSON payload, also has a limit, typically around 256 KB.

When you call PutEvents, the response will indicate the success or failure of each individual event within the batch. A FailedEntryCount greater than zero signifies that at least one event in the batch failed to be published. The response will also include an Entries list containing EventResponseEntry objects, each with an ErrorCode and ErrorMessage if the corresponding entry failed. This allows for granular error handling, where you might retry only the failed events.

The Time field in each event entry is not strictly required but is highly recommended. If omitted, EventBridge will assign the current server time, which might lead to slight discrepancies if the event is processed with a delay. Using datetime.utcnow() ensures a consistent timestamp.

The primary levers you control are the structure of your Detail payloads and how you group events into batches. Designing your event payloads to be as small as possible while still containing necessary information can help you maximize the number of events within the batch size limit.

The PutEvents API is idempotent if you include an IdempotencyToken in each Event object. This token, a unique string that you generate, allows EventBridge to detect and discard duplicate PutEvents requests. If you send the same PutEvents request twice with the same IdempotencyToken, EventBridge will process it only once and return the same response for the second request.

Want structured learning?

Take the full Eventbridge course →