Key matching
Use the exists operator in a filter policy to match incoming
messages based on whether a specific property is present or absent.
-
existsworks only on leaf nodes (final attributes in the structure). -
It does not apply to intermediate nodes within a nested JSON structure.
-
Use
"exists": trueto match incoming messages that include the specified property. The key must have a non-null and non-empty value.For example, the following policy property uses the
existsoperator with a value oftrue:"store": [{"exists": true}]It matches any list of message attributes that contains the
storeattribute key, such as the following:"store": {"Type": "String", "Value": "fans"} "customer_interests": {"Type": "String.Array", "Value": "[\"baseball\", \"basketball\"]"}It also matches either of the following message body:
{ "store": "fans" "customer_interests": ["baseball", "basketball"] }However, it doesn't match any list of message attributes without the
storeattribute key, such as the following:"customer_interests": {"Type": "String.Array", "Value": "[\"baseball\", \"basketball\"]"}Nor does it match the following message body:
{ "customer_interests": ["baseball", "basketball"] } -
Use
"exists": falseto match incoming messages that don't include the specified property.Note
"exists": falseonly matches if at least one attribute is present. An empty set of attributes results in the filter not matching.For example, the following policy property uses the
existsoperator with a value offalse:"store": [{"exists": false}]It doesn't match any list of message attributes that contains the
storeattribute key, such as the following:"store": {"Type": "String", "Value": "fans"} "customer_interests": {"Type": "String.Array", "Value": "[\"baseball\", \"basketball\"]"}It also doesn’t match the following message body:
{ "store": "fans" "customer_interests": ["baseball", "basketball"] }However, it matches any list of message attributes without the
storeattribute key, such as the following:"customer_interests": {"Type": "String.Array", "Value": "[\"baseball\", \"basketball\"]"}It also matches the following message body:
{ "customer_interests": ["baseball", "basketball"] }