EventBridge uses event patterns to filter and route events to targets. An event pattern is a module provided by EventBridge that defines matching criteria -- only events whose structure and values match the pattern are delivered to the target. Event patterns must have the same structure as the matched events.
How matching works
EventBridge evaluates each incoming event against your pattern using these rules:
| Rule | Description |
|---|---|
| Structural match | The event must contain every field in the pattern, with identical nesting. |
| Case-sensitive comparison | Characters are compared as-is. EventBridge does not normalize or modify strings during matching. |
| JSON values only | Event values must be valid JSON: double-quoted strings, unquoted numbers, or the keywords true, false, and null. |
| AND across keys, OR within arrays | Multiple keys in a pattern use AND logic. Multiple values in a single key's array use OR logic. |
Operator reference
Use the following table to find the right operator for your filtering needs. Detailed syntax and examples follow in each section.
| Operator | What it does | Syntax example |
|---|---|---|
| Exact value | Matches a specific field value | "source": ["acs.oss"] |
| Prefix | Matches the beginning of a string | "source": [{"prefix": "acs."}] |
| Suffix | Matches the end of a string | "subject": [{"suffix": ".jpg"}] |
| Contains | Matches a substring within a value | "type": [{"contains": "Normal"}] |
| Anything-but | Excludes specific values | "state": [{"anything-but": "initializing"}] |
| Numeric | Matches a number or numeric range | "c-count": [{"numeric": [">", 0, "<=", 5]}] |
| CIDR | Matches an IPv4 address range | "source-ip": [{"cidr": "10.0.0.0/24"}] |
| Exists | Checks whether a field exists | "state": [{"exists": false}] |
| Null / empty string | Matches null or "" values |
"responseElements": [null] |
| Array | Matches any value in an array | "subject": ["val1", "val2"] |
| Combined | Combines multiple operators | See Combined match |
Exact value match
To match events where a field equals a specific value, wrap the value in an array.
Pattern:
{
"source": ["acs.oss"]
}
This pattern matches events where source is "acs.oss". Events with a different source, such as "acs.ecs" or "acs.imm", do not match.
Example -- The following OSS event matches because source is "acs.oss":
{
"id": "7adc8c1a-645d-4476-bdef-5d6fb57f****",
"source": "acs.oss",
"specversion": "1.0",
"type": "oss:ObjectCreated:PostObject",
"datacontenttype": "application/json",
"dataschema": "http://example.com/test.json",
"subject": "acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg",
"time": "2020-08-17T16:04:46.149Asia/Shanghai",
"data": {
"name": "test",
"scope": 100
}
}
Events with a different source do not match:
-
An event with
"source": "acs.ecs"(Elastic Compute Service) -
An event with
"source": "acs.imm"(Intelligent Media Management)
Prefix match
To match events where a field value starts with a specific string, use the prefix operator.
Pattern:
{
"source": [{"prefix": "acs."}]
}
This pattern matches events where source starts with "acs.", such as "acs.oss" and "acs.imm".
Suffix match
To match events where a field value ends with a specific string, use the suffix operator.
Combine prefix and suffix in the same array to apply both conditions. Multiple suffix entries use OR logic -- the event matches if any suffix matches.
Pattern:
{
"subject": [
{"prefix": "acs:oss:cn-hangzhou:1234567:xls-papk/"},
{"suffix": ".txt"},
{"suffix": ".jpg"}
]
}
This pattern matches events where subject starts with the specified OSS path prefix AND ends with .txt or .jpg. An event with subject ending in .png does not match.
Contains match
To match events where a field value contains a specific substring, use the contains operator.
Single substring:
{
"type": [{"contains": "Normal"}]
}
Matches events like "type": "UserNormalEvent". Does not match "type": "UserErrorEvent".
Multiple substrings (OR logic):
{
"type": [
{"contains": "Normal"},
{"contains": "Error"}
]
}
Matches events where type contains either "Normal" or "Error". Both "UserNormalEvent" and "UserErrorEvent" match. "UserOtherEvent" does not.
Anything-but match
To exclude events that match specific values, use the anything-but operator. Events with any other value for the specified field pass through.
Exclude a single string
{
"data": {
"state": [{"anything-but": "initializing"}]
}
}
Matches events where data.state is any value except "initializing". For example, "state": "running" matches.
Exclude a single number
{
"data": {
"x-limit": [{"anything-but": 123}]
}
}
Matches events where data.x-limit is any value except 123. For example, "x-limit": 456 matches.
Exclude multiple strings
{
"data": {
"state": [{"anything-but": ["stopped", "overloaded"]}]
}
}
Matches events where data.state is any value except "stopped" or "overloaded". For example, "state": "terminated" matches.
Exclude multiple numbers
{
"data": {
"x-limit": [{"anything-but": [100, 200, 300]}]
}
}
Matches events where data.x-limit is any value except 100, 200, or 300. For example, "x-limit": 456 matches.
Exclude by prefix
{
"data": {
"state": [{"anything-but": {"prefix": "init"}}]
}
}
Matches events where data.state does not start with "init". For example, "state": "pending" matches, but "state": "initializing" does not.
Exclude a specific event source
{
"source": [{"anything-but": ["acs.ecs"]}]
}
Matches events from any source except "acs.ecs". For example, events from "acs.oss" match.
Exclude all Alibaba Cloud service events
{
"source": [{"anything-but": {"prefix": "acs."}}]
}
Matches only events from custom (non-Alibaba Cloud) sources. Any event with a source starting with "acs." is excluded.
Numeric match
To match events based on numeric values or ranges, use the numeric operator with one or more comparison operators.
| Comparison operator | Description |
|---|---|
= |
Equal to |
> |
Greater than |
>= |
Greater than or equal to |
< |
Less than |
<= |
Less than or equal to |
Define a range by placing two operators in the same array.
Single condition:
{
"data": {
"d-count": [{"numeric": ["<", 10]}]
}
}
Matches events where data.d-count is less than 10.
Range condition:
{
"data": {
"c-count": [{"numeric": [">", 0, "<=", 5]}]
}
}
Matches events where data.c-count is greater than 0 and less than or equal to 5.
Exact numeric value:
{
"data": {
"x-limit": [{"numeric": ["=", 301.8]}]
}
}
Matches events where data.x-limit equals 301.8. An event with "x-limit": 300 does not match.
Multiple numeric conditions across fields:
{
"data": {
"c-count": [{"numeric": [">", 0, "<=", 5]}],
"d-count": [{"numeric": ["<", 10]}],
"x-limit": [{"numeric": ["=", 301.8]}]
}
}
All three conditions must be true (AND logic across keys).
Numeric matching works only with JSON-formatted numbers in the range -1.0e9 to +1.0e9, with precision up to 15 digits and 6 decimal places.
IP address match
To match events based on an IPv4 address or CIDR block, use the cidr operator on a field in the data object.
Pattern:
{
"data": {
"source-ip": [{"cidr": "10.0.0.0/24"}]
}
}
Matches events where data.source-ip falls within the 10.0.0.0/24 range. For example, "source-ip": "10.0.0.123" matches, but "source-ip": "192.168.0.123" does not.
Only IPv4 addresses are supported.
Combined match
Combine multiple operators in a single pattern for precise filtering. Conditions across different fields use AND logic -- every condition must be true for the event to match.
The following pattern combines prefix, anything-but, CIDR, and numeric operators:
{
"source": [{"prefix": "acs."}],
"data": {
"state": [{"anything-but": "initializing"}],
"source-ip": [{"cidr": "10.0.0.0/24"}],
"c-count": [{"numeric": [">", 0, "<=", 5]}],
"d-count": [{"numeric": ["<", 10]}],
"x-limit": [{"anything-but": [100, 200, 300]}]
}
}
This event matches only when all conditions are true:
-
sourcestarts with"acs." -
data.stateis not"initializing" -
data.source-ipis in the10.0.0.0/24range -
data.c-countis greater than0and at most5 -
data.d-countis less than10 -
data.x-limitis not100,200, or300
Match example:
An event with source: "acs.oss", state: "pending", source-ip: "10.0.0.123", c-count: 5, d-count: 7, and x-limit: 301.8 satisfies all conditions.
Non-match example:
An event with state: "initializing" and source-ip: "192.168.0.123" fails the anything-but and CIDR conditions.
Array match
When a pattern field lists multiple values in an array, the event matches if its field value equals any value in that array. If the event field itself is an array, the event matches when the two arrays share at least one common element.
Single value in the event, multiple values in the pattern:
{
"subject": [
"acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg",
"acs:oss:cn-hangzhou:1112223:xls-papk/game_apk/123.jpg",
"acs:oss:cn-hangzhou:4455667:xls-papk/game_apk/123.jpg"
]
}
Matches if the event's subject equals any of the three values.
Array value in the event:
If the event contains "subject": ["acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg", "acs.ecs:cn-hangzhou:123456789098****:215672"], it matches because the first element appears in both the pattern array and the event array.
Null and empty string match
To match events where a field is null or an empty string "", wrap the target value in an array.
Match an empty string:
{
"data": {
"eventVersion": [""]
}
}
Matches events where data.eventVersion is "". Does not match if the value is "1.0".
Match a null value:
{
"data": {
"responseElements": [null]
}
}
Matches events where data.responseElements is null. Does not match if the value is "lss" or any other non-null value.
Null and empty string are distinct values. A pattern that matches "" does not match null, and vice versa.
Field existence match
To match events based on whether a field exists in the data object, use the exists operator.
Match when a field does not exist:
{
"data": {
"state": [{"exists": false}]
}
}
Matches events where the data object does not contain a state field. If state is present with any value (including null), the event does not match.
Match when a field exists:
{
"data": {
"state": [{"exists": true}]
}
}
Matches events where the data object contains a state field, regardless of its value.