Skip to main content
A subscription filter selects which published messages produce a delivery for that subscription. Put routing values in the publication’s attributes map. Putting an event field inside the JSON text of message does not make it a filterable attribute.

A complete example

This subscription policy accepts production orders worth at least 100 and less than 1,000, unless the publication carries a test attribute:
These publication attributes match:
Attribute values are strings even when their type is Number. Numeric matcher operands are JSON numbers. Keep those two representations distinct.

How conditions combine

Every attribute named by a policy must match: AND across attribute names. Within one attribute’s array, any alternative can match: OR across alternatives. Inside a single numeric operator, every comparison must succeed. Names and string matches are case-sensitive. An empty policy {} matches all messages, including messages with no attributes. Every matcher except exists: false requires that the attribute be present. A missing attribute therefore does not match an exclusion such as anything-but.

Supported matchers

The examples below show the alternatives array for one attribute. Supported numeric operators are =, <, <=, >, and >=. Write an operator followed by its numeric operand; repeat pairs to form a range. A value that cannot be parsed as a number does not match numeric conditions. The current evaluator parses the value for numeric comparisons regardless of its declared attribute type; use Number for numeric data for clarity. Bare JSON numbers are also accepted as exact alternatives, but they compare their string representation. [100] matches the attribute value "100", not "100.0". Use numeric for mathematical equality. A prefix or suffix matches literal text. There are no wildcards, regular expressions, nested body matching, array-valued message attributes, or case-insensitive operators. Do not assume every SNS filter operator is supported.

Combining presence and exclusion

To accept a value other than test, including publications where the attribute is absent, include both alternatives:
To require a prefix and a suffix on the same value, two entries in the array will not work: they mean OR. Publish a separate routing attribute with the combined classification if your application needs that condition.

Set or clear a policy

Open a topic’s Subscriptions tab and select Subscribe. Paste a JSON object into Filter policy on the creation page. Leave it empty to receive every message. The form checks JSON syntax; the API validates operators and limits.Open an existing subscription’s Filter policy tab to inspect its policy; use the API to replace or clear it.

Limits and validation

Each operator object must have exactly one operator. Prefix and suffix strings must be nonempty. Numeric lists must contain complete operator/number pairs. Empty alternatives arrays and unknown operators are invalid. Malformed policies return HTTP 400 with NOTIFICATION_INVALID_FILTER_POLICY. A filtered-out subscription has no delivery record and is not a failed attempt. If a publication reports fewer deliveries than expected, check the subscription confirmation status, exact attribute names and values, and every condition in the policy. A policy change affects fan-out decisions made after the change; it does not retroactively create or remove existing delivery records.