Sub topic 2
Anatomy of an EventBridge event
This chapter assumes you can read JSON, have used the AWS CLI, and know what an event bus is at a high level. By the end you should be able to name every field in an EventBridge event, say who sets each one, and avoid the mistakes people make when they build events by hand.
The event is a JSON envelope
Every event that EventBridge routes is a JSON object. Some top-level fields form an envelope, and one field, detail, carries your own data. Rules match against this whole object, so the field names and positions decide what your event patterns can look like.
Here is the event that the example PutEvents call in this tutorial produces, as a rule target would receive it:
{
"version": "0",
"id": "6a7e8feb-b491-4cf7-a9f1-bf3703467718",
"detail-type": "OrderPlaced",
"source": "com.example.orders",
"account": "123456789012",
"time": "2026-11-26T18:35:04Z",
"region": "us-east-1",
"resources": [],
"detail": {
"orderId": "1001",
"amount": 250,
"status": "new"
}
}The envelope fields
| Field | Type | Set by | Purpose |
|---|---|---|---|
| `version` | string | EventBridge | Envelope format version. It is `"0"` for all events today. |
| `id` | string | EventBridge | A unique identifier (a UUID) for this event. |
| `detail-type` | string | Producer | A human-readable label for the kind of event, such as `OrderPlaced`. |
| `source` | string | Producer | Identifies who produced the event. |
| `account` | string | EventBridge | The 12-digit account ID of the sender. |
| `time` | string | Producer or EventBridge | The event timestamp in UTC. It defaults to the time EventBridge received the event. |
| `region` | string | EventBridge | The Region where the event was received. |
| `resources` | array of strings | Producer | ARNs of resources the event is about. It can be empty. |
| `detail` | object | Producer | The payload. Its structure is up to you. |
Producers control four of these fields directly: source, detail-type, resources, and detail. They can also override time. EventBridge fills in the rest. A producer cannot forge account or region, so a rule can rely on them to know where an event really came from.
Naming differs between the API and the event
The same field has two spellings depending on where you meet it. In a PutEvents request the keys use PascalCase: Source, DetailType, Detail, Resources, Time. In the delivered event and in event patterns the keys are lowercase, and DetailType becomes detail-type, with a hyphen.
This mismatch is a common source of patterns that never match. A pattern that uses "DetailType" or "detailType" looks for a key that does not exist in the event, so the rule matches nothing. EventBridge does not warn you about this. Always write patterns against the delivered event shape, never the request shape.
`source`: a namespace for producers
The source value tells rules which system emitted the event. AWS services use the aws. prefix, for example aws.s3 or aws.ec2. That prefix is reserved, so your own events cannot use it. For custom events, the usual convention is reverse-DNS naming such as com.example.orders. It avoids collisions and makes ownership obvious.
Rules often filter on source first, because it is the cheapest way to narrow a stream to one producer. Pick a stable value and treat it as part of your contract. If you rename the source, every rule that matches the old name stops matching.
`detail-type`: what happened
detail-type says what kind of event this is. Use it to describe a fact in the past tense or a state change, such as OrderPlaced or PaymentFailed. AWS services use phrases like EC2 Instance State-change Notification. Together, source and detail-type act like a name for the event schema. A consumer can usually decide whether it cares about an event from these two fields without opening detail.
Keep detail-type low in cardinality. Putting an order ID or timestamp in it makes patterns hard to write and defeats its purpose. Variable data belongs in detail.
`detail`: your payload
For custom events, detail must be a JSON object. A bare string, number, or array is rejected. Beyond that, EventBridge imposes no schema. Rules can reach into any nested field, so keep the payload flat and predictable where you can.
Design the payload with the consumers in mind:
- Include the identifiers a consumer needs to look up more data, such as
orderId. - Include fields that rules will filter on, such as
amountandstatus, so rules can route without a lookup. - Avoid putting large blobs in the event. Store the blob elsewhere (for example in Amazon S3) and put a reference in
detail. - Treat the field names as a public interface. Renaming one is a breaking change for every rule that matches on it.
`resources`, `time`, and `id`
resources is an array of ARNs that the event concerns. AWS service events fill it in, for example with the ARN of an instance that changed state. For custom events it is optional and often left empty. It is still useful: patterns can match on it, and it helps humans reading the event later.
time is in UTC. If the producer does not set Time, EventBridge uses the moment it received the event. Set Time yourself only when the event describes something that happened earlier, such as when you are backfilling. The time is not a delivery guarantee or an ordering key. Events can be delivered out of order, and consumers should not assume time reflects arrival order.
id uniquely identifies the event. It is useful for logging and for tracing an event through your systems. EventBridge offers at-least-once delivery to targets, so a consumer can see the same event twice. Use id as an idempotency key to detect duplicates.
Building an event with the CLI
In PutEvents, Detail is a JSON string that contains an object, not a nested object. Every quote inside it has to be escaped. This is the most frequent mistake in hand-written calls.
aws events put-events --entries '[{"Source":"com.example.orders","DetailType":"OrderPlaced","Detail":"{\"orderId\":\"1001\",\"amount\":250,\"status\":\"new\"}","Resources":["arn:aws:example:us-east-1:123456789012:order/1001"],"EventBusName":"orders-bus"}]'If you pass Detail as a nested object instead of a string, the CLI rejects the call during parameter validation. If the string holds invalid JSON, the entry fails on the service side with an ErrorCode such as MalformedDetail.
In Python, json.dumps removes the escaping problem:
import json
import boto3
events = boto3.client("events")
detail = {"orderId": "1001", "amount": 250, "status": "new"}
response = events.put_events(
Entries=[
{
"Source": "com.example.orders",
"DetailType": "OrderPlaced",
"Detail": json.dumps(detail),
"Resources": ["arn:aws:example:us-east-1:123456789012:order/1001"],
"EventBusName": "orders-bus",
}
]
)
print(response["FailedEntryCount"])Size limits
An entry, which is one event, can be at most 256 KB. EventBridge computes the size from the UTF-8 bytes of Source, DetailType, Detail, and each item in Resources, plus a fixed amount for Time. A single PutEvents request can carry up to 10 entries, and the whole request must also fit within 256 KB. An entry over the limit fails with an error rather than being truncated.
Multi-byte characters count by their byte length, not their character count. A payload full of non-Latin text reaches the limit sooner than its character count suggests.
How rules see the event
A rule's event pattern is matched against the complete envelope, not only against detail. A pattern can therefore combine envelope and payload conditions:
{
"source": ["com.example.orders"],
"detail-type": ["OrderPlaced"],
"region": ["us-east-1"],
"detail": {
"status": ["new"]
}
}The next chapters cover how patterns work in detail. For now, notice that the pattern's structure mirrors the event's structure. Each pattern key refers to a field at the same position in the event, and each value is an array of acceptable matches. If you know the event's shape, you know where to put each condition.
Common errors
- Using request-style key names in patterns. Use
detail-type, notDetailType. - Passing
Detailas an object. It must be a string that contains a JSON object. - Putting a non-object in
Detail. A string, number, or array in theDetailstring is rejected. - Using the
aws.prefix inSource. That prefix is reserved for AWS services. - Ignoring partial failure. Check
FailedEntryCountafter every call. - Putting variable data in
detail-type. Keep it to a small, stable set of values. - Relying on
timefor ordering. Delivery is not ordered bytime.
Exercise
A teammate's rule never matches the events your service publishes. The service calls PutEvents with Source "com.example.billing" and DetailType "InvoicePaid". The rule's pattern is {"source": ["com.example.billing"], "DetailType": ["InvoicePaid"]}. What is wrong, and what is the corrected pattern?
Show answer
The pattern uses the API key name DetailType. In the delivered event the field is called detail-type, so the pattern looks for a key that does not exist and matches nothing. The corrected pattern is {"source": ["com.example.billing"], "detail-type": ["InvoicePaid"]}.
Exercise
You publish an event with Resources set to an empty array and no Time. Which envelope fields does EventBridge add or fill in, and which of them could a producer never set to a false value?
Show answer
EventBridge adds version, id, account, and region, and it fills in time with the moment it received the event. A producer cannot falsify account or region, because EventBridge sets them, which lets rules trust them as the true sender account and Region.