All Products
Search
Document Center

EventBridge:Calculate the size of events published by PutEvents

Last Updated:Mar 11, 2026

The PutEvents operation accepts multiple custom events in a single request, but the total size of all events in the request must not exceed 256 KB (262,144 bytes). Calculate the size of each CloudEvent before batching to stay within this limit.

How event size is calculated

A CloudEvent consists of metadata attributes and a data payload. The total size equals the sum of the UTF-8 byte length of each attribute plus the raw byte length of the data field.

AttributeSize calculation
timeGenerally 36 bytes
specversionUTF-8 encoded byte length
idUTF-8 encoded byte length
typeUTF-8 encoded byte length
sourceUTF-8 encoded byte length
subjectUTF-8 encoded byte length
dataschemaUTF-8 encoded byte length
datacontenttypeUTF-8 encoded byte length
dataRaw byte array length (byte[])

Sample code

Calculate the size of a single CloudEvent (Java):

int getSize(CloudEvent event) {
    int size = 0;

    // time is generally a 36-byte timestamp when present
    if (event.getTime() != null) {
        size += 36;
    }

    // Metadata attributes: measure UTF-8 encoded byte length
    size += event.getSpecversion().getBytes(StandardCharsets.UTF_8).length;
    size += event.getId().getBytes(StandardCharsets.UTF_8).length;
    size += event.getType().getBytes(StandardCharsets.UTF_8).length;
    size += event.getSource().toString().getBytes(StandardCharsets.UTF_8).length;
    size += event.getSubject().getBytes(StandardCharsets.UTF_8).length;
    size += event.getDataschema().toString().getBytes(StandardCharsets.UTF_8).length;
    size += event.getDatacontenttype().getBytes(StandardCharsets.UTF_8).length;

    // Data payload: measure raw byte array length
    size += event.getData().length;

    return size;
}