AWS Event Bridge 规则匹配同一 S3 存储桶中的两个特定目录

问题描述 投票:0回答:1

当文件上传到任何目录时,我希望事件桥规则能够匹配同一 S3 存储桶的两个不同目录(前缀)。

如果我将两个前缀对象放在detail.object.key下,则规则仅匹配最后一个对象,按照下面的事件模式:

{ 
  "source": ["aws.s3"],
  "detail-type": ["Object Created"],
  "detail": { 
    "bucket": { "name": ["some-bucket"] },
    "object": {
      "key": [
        { "prefix": "some-prefix/" },
        { "prefix": "some-other-prefix/" }
      ] 
    } 
  } 
}

文档不清楚如何实现这一点。

amazon-web-services amazon-s3 amazon-cloudwatch aws-serverless aws-event-bridge
1个回答
0
投票

我找到了一种使用基于内容的过滤和 $or 匹配来做到这一点的方法。

https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-event-patterns-content-based-filtering.html#eb-filtering-complex-example-or

文档仍然不清楚具体的用例,但经过几次试验和错误后,我通过声明事件模式来使其工作,如下所示:

{
  "source": ["aws.s3"],
  "detail-type": ["Object Created"],
  "detail": {
    "bucket": {
      "name": ["some-bucket"]
    },
    "$or": [
      {
        "object": {
          "key": [{
            "prefix": "some-prefix/"
          }]
        }
      },
      {
        "object": {
          "key": [{
            "prefix": "some-other-prefix/"
          }]
        }
      }
    ]
  }
}

希望有帮助!

© www.soinside.com 2019 - 2024. All rights reserved.