简体   繁体   English

如何创建匹配嵌套消息属性的 SNS 过滤策略?

[英]How to create a SNS Filter Policy that matches nested message attributes?

I've created an SNS topic, and I'd like to subscribe to it with a filter policy that matches a nested attribute.我创建了一个 SNS 主题,我想使用与嵌套属性匹配的过滤策略来订阅它。 For example, given a message like this:例如,给出这样的消息:

{
  "foo": {
    "bar": "baz"
  },
  "quux": "vorp"
}

I'd like to match only messages where the bar attribute of foo is equal to baz .我只想匹配foobar属性等于baz的消息。

The documentation I've found so far only mentions matching attributes specified at the top level.到目前为止我找到的文档只提到了在顶层指定的匹配属性。 I'm interested in a nested attribute.我对嵌套属性感兴趣。 For the purposes of this question, let's assume I don't control the structure of the message.出于这个问题的目的,让我们假设我不控制消息的结构。

Subscription filters don't act on the message (body, payload). 订阅筛选器不会对邮件(正文,有效负载)执行操作。 They only act on the message attributes . 它们仅对消息属性起作用。

Message attributes are not complex objects... their only types are string, string array, number, and binary. 消息属性不是复杂对象...它们唯一的类型是字符串,字符串数组,数字和二进制。 If a message attribute contains a serialized object (eg JSON), subscription filters aren't designed to support extracting/matching the serialized data inside. 如果消息属性包含序列化对象(例如JSON),则订阅过滤器不支持提取/匹配内部的序列化数据。

As of 2022, it's possible to filter based on the payload.从 2022 年开始,可以根据有效负载进行过滤。

That's mentioned here: https://docs.aws.amazon.com/sns/latest/dg/sns-message-filtering.html这里提到: https://docs.aws.amazon.com/sns/latest/dg/sns-message-filtering.html

An Example of filtering:过滤示例:

Let's say your original message is like:假设您的原始消息是这样的:

{
  "eventType": "SOME_STRING",
  "otherAttribs": "bla..."
}

Then the filter can be something like:然后过滤器可以是这样的:

{
  "eventType": [
    {
      "prefix": "SAMETH"
    }
  ]
}

In AWS WebConsole, it's found in SNS -> Subscriptions -> [select one] -> Subscription filter policy.在 AWS WebConsole 中,它位于 SNS -> 订阅 -> [选择一个] -> 订阅过滤策略中。

Now, SNS can filter events based on their payload as well.现在,SNS 也可以根据有效负载过滤事件。 With this release, the SNS filter policy can handle property nesting too.在此版本中,SNS 过滤策略也可以处理属性嵌套。 For more information, please take a look at: https://aws.amazon.com/blogs/compute/introducing-payload-based-message-filtering-for-amazon-sns/更多信息,请查看: https://aws.amazon.com/blogs/compute/introducing-payload-based-message-filtering-for-amazon-sns/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM