字串值比對 - Amazon Simple Notification Service

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

字串值比對

您可以比對字串值與訊息屬性值或訊息內文屬性值,以篩選訊息。在 JSON 政策中,字串值是以雙引號括住。您可以使用以下字串操作來比對訊息屬性或訊息內文。

完全符合

政策屬性值符合一或多個訊息屬性值時,即完全相符。

舉例下列政策屬性:

"customer_interests": ["rugby", "tennis"]

它符合以下訊息屬性:

"customer_interests": {"Type": "String", "Value": "rugby"}
"customer_interests": {"Type": "String", "Value": "tennis"}

它也符合以下訊息內文:

{ "customer_interests": "rugby" }
{ "customer_interests": "tennis" }

但不符合以下訊息屬性:

"customer_interests": {"Type": "String", "Value": "baseball"}

它也不符合以下訊息內文:

{ "customer_interests": "baseball" }

除外相符

當政策屬性值包含關鍵字 anything-but,就會比對包含任何政策屬性值的任何訊息屬性或訊息內文值。anything-but 可以與 "exists": false 結合。

舉例下列政策屬性:

"customer_interests": [{"anything-but": ["rugby", "tennis"]}]

它符合以下任一訊息屬性:

"customer_interests": {"Type": "String", "Value": "baseball"}
"customer_interests": {"Type": "String", "Value": "football"}

它也符合以下任一訊息內文:

{ "customer_interests": "baseball" }
{ "customer_interests": "football" }

除此之外,它符合以下訊息屬性 (因為它包含的值不是 rugbytennis):

"customer_interests": {"Type": "String.Array", "Value": "[\"rugby\", \"baseball\"]"}

它也符合以下訊息內文 (因為它包含的值不是 rugbytennis):

{ "customer_interests": ["rugby", "baseball"] }

但不符合以下訊息屬性:

"customer_interests": {"Type": "String", "Value": "rugby"}

它也不符合以下訊息內文:

{ "customer_interests": ["rugby"] }

使用具 anything-but 運算子的字首

針對字串比對,您也可以使用具 anything-but 運算子的字首。例如,下列政策屬性會拒絕 order- 字首:

"event":[{"anything-but": {"prefix": "order-"}}]

它符合以下任一屬性:

"event": {"Type": "String", "Value": "data-entry"}
"event": {"Type": "String", "Value": "order_number"}

它也符合以下任一訊息內文:

{ "event": "data-entry" }
{ "event": "order_number" }

但不符合以下訊息屬性:

"event": {"Type": "String", "Value": "order-cancelled"}

它也不符合以下訊息內文:

{ "event": "order-cancelled" }

電子quals-ignore-case 匹配

當政策屬性包含關鍵字 equals-ignore-case 時,將對任何訊息屬性或內文屬性值執行不分大小寫的比對。

舉例下列政策屬性:

"customer_interests": [{"equals-ignore-case": "tennis"}]

它符合以下任一訊息屬性:

"customer_interests": {"Type": "String", "Value": "TENNIS"}
"customer_interests": {"Type": "String", "Value": "Tennis"}

它也符合以下任一訊息內文:

{ "customer_interests": "TENNIS" }
{ "customer_interests": "teNnis" {

IP 地址比對

您可以使用 cidr 運算子來檢查傳入訊息是否來自特定 IP 地址或子網路。

舉例下列政策屬性:

"source_ip":[{"cidr": "10.0.0.0/24"}]

它符合以下任一訊息屬性:

"source_ip": {"Type": "String", "Value": "10.0.0.0"}
"source_ip": {"Type": "String", "Value": "10.0.0.255"}

它也符合以下任一訊息內文:

{ "source_ip": "10.0.0.0" }
{ "source_ip": "10.0.0.255" }

但不符合以下訊息屬性:

"source_ip": {"Type": "String", "Value": "10.1.1.0"}

它也不符合以下訊息內文:

{ "source_ip": "10.1.1.0" }

前綴相符

當政策屬性包含 prefix 關鍵字時,它符合任何以特定字元為開頭的訊息屬性或內文屬性值。

舉例下列政策屬性:

"customer_interests": [{"prefix": "bas"}]

它符合以下任一訊息屬性:

"customer_interests": {"Type": "String", "Value": "baseball"}
"customer_interests": {"Type": "String", "Value": "basketball"}

它也符合以下任一訊息內文:

{ "customer_interests": "baseball" }
{ "customer_interests": "basketball" }

但不符合以下訊息屬性:

"customer_interests": {"Type": "String", "Value": "rugby"}

它也不符合以下訊息內文:

{ "customer_interests": "rugby" }

後綴相符

當政策屬性包含 suffix 關鍵字時,它符合任何以特定字元為結束的訊息屬性或內文屬性值。

舉例下列政策屬性:

"customer_interests": [{"suffix": "ball"}]

它符合以下任一訊息屬性:

"customer_interests": {"Type": "String", "Value": "baseball"}
"customer_interests": {"Type": "String", "Value": "basketball"}

它也符合以下任一訊息內文:

{ "customer_interests": "baseball" }
{ "customer_interests": "basketball" }

但不符合以下訊息屬性:

"customer_interests": {"Type": "String", "Value": "rugby"}

它也不符合以下訊息內文:

{ "customer_interests": "rugby" }