# Match

Class · Stable

An event pattern matcher.

Implements: [IResolvable](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html)

- Source: [`aws-events/lib/event-pattern.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-events/lib/event-pattern.ts#L20)
- Type last changed: v2.172.0 · 7 Dec 2024

## Example

TypeScript:

```ts
const rule = new events.Rule(this, 'rule', {
  eventPattern: {
    detail: {
      object: {
        // Matchers may appear at any level
        size: events.Match.greaterThan(1024),
      },

      // 'OR' condition
      'source-storage-class': events.Match.anyOf(
        events.Match.prefix('GLACIER'),
        events.Match.exactString('DEEP_ARCHIVE'),
      ),
    },

    // If you prefer, you can use a low level array of strings, as directly consumed by EventBridge
    source: ['aws.s3'],

    region: events.Match.anythingButPrefix('us-gov'),
  },
});
```

Python:

```python
rule = events.Rule(self, "rule",
    event_pattern=events.EventPattern(
        detail={
            "object": {
                # Matchers may appear at any level
                "size": events.Match.greater_than(1024)
            },

            # 'OR' condition
            "source-storage-class": events.Match.any_of(
                events.Match.prefix("GLACIER"),
                events.Match.exact_string("DEEP_ARCHIVE"))
        },

        # If you prefer, you can use a low level array of strings, as directly consumed by EventBridge
        source=["aws.s3"],

        region=events.Match.anything_but_prefix("us-gov")
    )
)
```

Java:

```java
Rule rule = Rule.Builder.create(this, "rule")
        .eventPattern(EventPattern.builder()
                .detail(Map.of(
                        "object", Map.of(
                                // Matchers may appear at any level
                                "size", Match.greaterThan(1024)),

                        // 'OR' condition
                        "source-storage-class", Match.anyOf(Match.prefix("GLACIER"), Match.exactString("DEEP_ARCHIVE"))))

                // If you prefer, you can use a low level array of strings, as directly consumed by EventBridge
                .source(List.of("aws.s3"))

                .region(Match.anythingButPrefix("us-gov"))
                .build())
        .build();
```

C#:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
var rule = new Rule(this, "rule", new RuleProps {
    EventPattern = new EventPattern {
        Detail = new Dictionary<string, object> {
            { "object", new Dictionary<string, string[]> {
                // Matchers may appear at any level
                { "size", Match.GreaterThan(1024) }
            } },

            // 'OR' condition
            { "source-storage-class", Match.AnyOf(Match.Prefix("GLACIER"), Match.ExactString("DEEP_ARCHIVE")) }
        },

        // If you prefer, you can use a low level array of strings, as directly consumed by EventBridge
        Source = new [] { "aws.s3" },

        Region = Match.AnythingButPrefix("us-gov")
    }
});
```

Go:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
rule := events.NewRule(this, jsii.String("rule"), &RuleProps{
	EventPattern: &EventPattern{
		Detail: map[string]interface{}{
			"object": map[string][]*string{
				// Matchers may appear at any level
				"size": events.Match_greaterThan(jsii.Number(1024)),
			},

			// 'OR' condition
			"source-storage-class": events.Match_anyOf(events.Match_prefix(jsii.String("GLACIER")), events.Match_exactString(jsii.String("DEEP_ARCHIVE"))),
		},

		// If you prefer, you can use a low level array of strings, as directly consumed by EventBridge
		Source: []*string{
			jsii.String("aws.s3"),
		},

		Region: events.Match_AnythingButPrefix(jsii.String("us-gov")),
	},
})
```

## Properties

- `creationStack`: string[] — The creation stack of this resolvable which will be appended to errors thrown during resolution.

  This may return an array with a single informational element indicating how
  to get this property populated, if it was skipped for performance reasons.

## Methods

- `allOf(...matchers: any[]): string[]` (static) — Matches an event if any of the provided matchers do.

  Only numeric matchers are accepted.

- `anyOf(...matchers: any[]): string[]` (static) — Matches an event if any of the provided matchers does.

- `anythingBut(...values: any[]): string[]` (static) — Matches anything except what's provided in the rule.

  The list of provided values must contain
  only strings or only numbers.

- `anythingButEqualsIgnoreCase(...values: string[]): string[]` (static) — Matches any string that doesn't match with the given value regardless of character casing.

- `anythingButPrefix(...values: string[]): string[]` (static) — Matches any string that doesn't start with the given prefix.

- `anythingButSuffix(...values: string[]): string[]` (static) — Matches any string that doesn't end with the given suffix.

- `anythingButWildcard(...values: string[]): string[]` (static) — Matches any string that doesn't match with the given wildcard pattern.

- `asList(): string[]` — A representation of this matcher as a list of strings.

- `cidr(range: string): string[]` (static) — Matches IPv4 and IPv6 network addresses using the Classless Inter-Domain Routing (CIDR) format.

- `doesNotExist(): string[]` (static) — Matches when the field is absent from the JSON of the event.

- `equal(value: number): string[]` (static) — Matches numbers equal to the provided value.

- `equalsIgnoreCase(value: string): string[]` (static) — Matches a string, regardless of case, in the JSON of the event.

- `exactString(value: string): string[]` (static) — Matches a string, exactly, in the JSON of the event.

- `exists(): string[]` (static) — Matches when the field is present in the JSON of the event.

- `greaterThan(value: number): string[]` (static) — Matches numbers greater than the provided value.

- `greaterThanOrEqual(value: number): string[]` (static) — Matches numbers greater than, or equal to, the provided value.

- `interval(lower: number, upper: number): string[]` (static) — Matches numbers inside a closed numeric interval. Equivalent to:.

  Match.allOf(Match.greaterThanOrEqual(lower), Match.lessThanOrEqual(upper))

  **Parameters**

  - `lower` — Lower bound (inclusive).
  - `upper` — Upper bound (inclusive).

- `ipAddressRange(range: string): string[]` (static) — Matches IPv4 and IPv6 network addresses using the Classless Inter-Domain Routing (CIDR) format.

  Alias of `cidr()`.

- `lessThan(value: number): string[]` (static) — Matches numbers less than the provided value.

- `lessThanOrEqual(value: number): string[]` (static) — Matches numbers less than, or equal to, the provided value.

- `nullValue(): string[]` (static) — Matches a null value in the JSON of the event.

- `prefix(value: string): string[]` (static) — Matches strings with the given prefix in the JSON of the event.

- `prefixEqualsIgnoreCase(value: string): string[]` (static) — Matches strings with the given prefix in the JSON of the event regardless of the casing.

- `resolve(context: IResolveContext): any` — Produce the Token's value at resolution time.

- `suffix(value: string): string[]` (static) — Matches strings with the given suffix in the JSON of the event.

- `suffixEqualsIgnoreCase(value: string): string[]` (static) — Matches strings with the given suffix in the JSON of the event regardless of the casing.

- `toString(): string` — Return a string representation of this resolvable object.

  Returns a reversible string representation.

- `wildcard(value: string): string[]` (static) — Matches strings with the given wildcard pattern in the JSON of the event.
