An event pattern is a module provided by EventBridge to filter events. EventBridge filters events by matching them against event patterns and then routes matched events to event targets. Event patterns must have the same structure as the matched events. Only events that match all conditions in the pattern are forwarded.
How event pattern matching works
Event patterns follow these matching rules:
Structural matching: The event must contain every field specified in the pattern, with the same nested structure. Fields in the event that are not in the pattern are ignored.
Case sensitivity: All string comparisons are case-sensitive. EventBridge does not modify strings during matching.
JSON values: Matched values must be valid JSON -- strings in double quotes (
""), numbers, or unquoted keywords (true,false,null).Logical operators: Keys in a pattern are combined with AND logic. Values in an array for the same key are combined with OR logic.
Operator quick reference
All available pattern operators are listed below, with detailed examples in the sections that follow.
| Operator | Description | Syntax example |
|---|---|---|
| Exact value | Match a specific field value | "source": ["acs.oss"] |
prefix | Match values that start with a string | "source": [{"prefix": "acs."}] |
suffix | Match values that end with a string | "subject": [{"suffix": ".jpg"}] |
contains | Match values that include a substring | "type": [{"contains": "Normal"}] |
anything-but | Exclude specific values | "state": [{"anything-but": "initializing"}] |
anything-but (prefix) | Exclude values by prefix | "source": [{"anything-but": {"prefix": "acs."}}] |
numeric | Match a numeric value or range | "count": [{"numeric": [">", 0, "<=", 5]}] |
cidr | Match an IPv4 address in a CIDR block | "source-ip": [{"cidr": "10.0.0.0/24"}] |
| Array | Match any value in a list | "subject": ["value1", "value2"] |
| Null / empty string | Match null or "" | "field": [null] or "field": [""] |
exists | Match based on field presence | "state": [{"exists": false}] |
Event structure reference
All examples in this topic use events based on the CloudEvents specification. The full event structure is shown below for reference -- subsequent examples include only the fields relevant to each operator.
{
"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
}
}Exact value matching
Match events where a field equals a specific value. Specify the target value in an array.
Pattern -- match events from acs.oss:
{
"source": ["acs.oss"]
}Match result: An event with "source": "acs.oss" matches. An event with "source": "acs.aliyuncvc" or "source": "acs.imm" does not.
Prefix matching
Match events where a field value starts with a specified string. Use the prefix operator.
Pattern -- match events where source starts with acs.:
{
"source": [
{
"prefix": "acs."
}
]
}Match result: Both "source": "acs.oss" and "source": "acs.imm" match, because both start with acs..
Substring matching (contains)
Match events where a field value includes a specified substring.
Single substring
Pattern -- match events where type contains Normal:
{
"type": [
{
"contains": "Normal"
}
]
}Match result: "type": "UserNormalEvent" matches. "type": "UserErrorEvent" does not.
Multiple substrings (OR)
Specify multiple contains entries to match any of them.
Pattern -- match events where type contains Normal or Error:
{
"type": [
{
"contains": "Normal"
},
{
"contains": "Error"
}
]
}Match result: Both "type": "UserNormalEvent" and "type": "UserErrorEvent" match. "type": "UserOtherEvent" does not.
Suffix matching
Match events where a field value ends with a specified string. Use the suffix operator. Combine prefix and suffix in the same array to narrow the match.
Pattern -- match events where subject starts with acs:oss:cn-hangzhou:1234567:xls-papk/ and ends with .txt or .jpg:
{
"subject": [
{
"prefix": "acs:oss:cn-hangzhou:1234567:xls-papk/"
},
{
"suffix": ".txt"
},
{
"suffix": ".jpg"
}
]
}Match result: A subject of "acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg" matches. A subject ending in .png does not.
Exclusion matching (anything-but)
Match events where a field value does not equal a specified value. The anything-but operator supports strings, numbers, lists, and prefix exclusion.
Exclude a single string
Pattern -- match events where data.state is not initializing:
{
"data": {
"state": [
{
"anything-but": "initializing"
}
]
}
}Match result: "state": "running" matches. "state": "initializing" does not. If the state field does not exist in the event, the event also does not match.
Exclude a single number
Pattern -- match events where data.x-limit is not 123:
{
"data": {
"x-limit": [
{
"anything-but": 123
}
]
}
}Combine multiple anything-but rules in the same data object. Keys are joined with AND logic, so both conditions must be satisfied:
{
"data": {
"state": [
{
"anything-but": "initializing"
}
],
"x-limit": [
{
"anything-but": 123
}
]
}
}Exclude multiple strings
Pass an array to anything-but to exclude more than one value.
Pattern -- match events where data.state is neither stopped nor overloaded:
{
"data": {
"state": [
{
"anything-but": [
"stopped",
"overloaded"
]
}
]
}
}Match result: "state": "terminated" matches. "state": "stopped" does not.
Exclude multiple numbers
Pattern -- match events where data.x-limit is not 100, 200, or 300:
{
"data": {
"x-limit": [
{
"anything-but": [
100,
200,
300
]
}
]
}
}Match result: "x-limit": 456 matches. "x-limit": 200 does not.
Exclude by prefix
Pattern -- match events where data.state does not start with init:
{
"data": {
"state": [
{
"anything-but": {
"prefix": "init"
}
}
]
}
}Match result: "state": "pending" matches. "state": "initializing" does not.
Exclude a specific source
Pattern -- match events not from Cloud Video Conferencing (acs.aliyuncvc):
{
"source": [
{
"anything-but": [
"acs.aliyuncvc"
]
}
]
}Exclude all Alibaba Cloud sources
Pattern -- match only events from custom applications (sources that do not start with acs.):
{
"source": [
{
"anything-but": {
"prefix": "acs."
}
}
]
}Numeric matching
Match events based on numeric values or ranges. Use the numeric operator with comparison operators: =, >, >=, <, <=. Specify a range by combining two comparisons in the same array.
Pattern -- match events where:
data.c-countis greater than 0 and less than or equal to 5data.d-countis less than 10data.x-limitequals 301.8
{
"data": {
"c-count": [
{
"numeric": [">", 0, "<=", 5]
}
],
"d-count": [
{
"numeric": ["<", 10]
}
],
"x-limit": [
{
"numeric": ["=", 301.8]
}
]
}
}Match result: An event with "c-count": 5, "d-count": 7, "x-limit": 301.8 matches. Changing x-limit to 300 breaks the match.
Numeric matching applies only to JSON-formatted numbers in the range -1.0e9 to +1.0e9, with precision up to 15 digits and 6 decimal places.
IP address matching (cidr)
Match events based on an IPv4 address in CIDR notation. Use the cidr operator on a field inside data.
Pattern -- match events where data.source-ip is in the 10.0.0.0/24 subnet:
{
"data": {
"source-ip": [
{
"cidr": "10.0.0.0/24"
}
]
}
}Match result: "source-ip": "10.0.0.123" matches. "source-ip": "192.168.0.123" does not.
Only IPv4 addresses are supported. IPv6 is not available for CIDR matching.
Combined conditions
Combine multiple operators in a single pattern for precise filtering. All conditions are joined with AND logic -- every condition must be satisfied.
Pattern -- match events where:
sourcestarts withacs.data.stateis notinitializingdata.source-ipis in the10.0.0.0/24subnetdata.c-countis greater than 0 and at most 5data.d-countis less than 10data.x-limitis not100,200, or300
{
"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]
}
]
}
}Match result: 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 matches. Changing state to "initializing" or source-ip to "192.168.0.123" breaks the match.
Array matching
Pattern values are always arrays. If a field value in the event is also an array, the event matches when the two arrays share at least one common element (non-empty intersection).
Pattern -- match events with specific subject values:
{
"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"
]
}Match result: An event with "subject": "acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg" matches (exact value in the array).
An event with an array-valued subject also matches if the arrays overlap:
{
"subject": [
"acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg",
"acs:acs.aliyuncvc:cn-hangzhou:<yourAccountId>:215672"
]
}This matches because acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg appears in both arrays.
Null and empty string matching
Match events where a field is null or an empty string ("").
Empty string
Pattern -- match events where data.eventVersion is an empty string:
{
"data": {
"eventVersion": [""]
}
}Match result: "eventVersion": "" matches. "eventVersion": "1.0" does not.
Null value
Pattern -- match events where data.responseElements is null:
{
"data": {
"responseElements": [null]
}
}Match result: "responseElements": null matches. "responseElements": "lss" does not.
null and "" are distinct values. A pattern that matches "" does not match null, and vice versa.
Field existence matching (exists)
Match events based on whether a field is present in the data object. Set exists to false to match events where the field is absent.
Pattern -- match events where data.state does not exist:
{
"data": {
"state": [
{
"exists": false
}
]
}
}Match result: An event with data containing only name and scope matches. An event where data also contains "state": "terminated" does not.