【问题标题】:Filtering AWS SNS messages by attribute value but only if attribute is present按属性值过滤 AWS SNS 消息,但前提是属性存在
【发布时间】:2022-08-20 18:29:10
【问题描述】:

我想知道如何为 AWS SNS 订阅创建一个过滤策略,该策略将检查消息属性值,但前提是该属性存在。默认情况下,如果我检查属性值但属性不存在,则忽略消息,例如:

\"customer_interests\": [\"paintball\"]

我还发现这个用于属性存在检查:

\"customer_interests\": [{\"exists\": true}]

但我不确定如何将这两项检查合并到一个策略中。

我已经尝试过显而易见的事情:

{
   \"customer_interests\": [{\"exists\": false}, \"paintball\"]
}

但它不起作用。

  • 我尝试了您的“显而易见的事情”,它对我有用。我的测试是 1. customer_interests = \"paintball\"(收到) 2. customer_interests = \"boxe\"(不是) 3. name = \"test\", no other attrs (received)
  • @AlbertoAnderickJr 奇怪我已经尝试过多次但没有任何运气......可能会再试一次。

标签: amazon-sns


【解决方案1】:

通过将多个值分配给属性名称,您可以在 SNS 订阅过滤策略中应用 OR 逻辑。

你的例子:

{
   "customer_interests": [{"exists": false}, "paintball"]
}

应该导致过滤消息:

  • 没有customer_interests消息属性
  • 或将customer_interests 消息属性设置为paintball

请注意,订阅过滤策略的添加或更改需要长达 15 分钟完全生效,因为 Amazon SNS 最终是一致的。

更改不会总是立即生效。

【讨论】:

    猜你喜欢
    • 2014-11-17
    • 1970-01-01
    • 1970-01-01
    • 2011-05-31
    • 1970-01-01
    • 2020-08-03
    相关资源
    最近更新 更多