简体   繁体   English

为什么 AWS EventBridge 规则不支持后缀匹配?

[英]Why AWS EventBridge Rules does not support Suffix Matching?

Unlike EventBridge, S3 Events supports both Prefix and Suffix since 2015. Reference: S3 Documents与 EventBridge 不同,S3 Events 自 2015 年起同时支持前缀和后缀。参考: S3 文档

As at 2022 August, from the documentation of EventBridge , it supports only following filter types:截至 2022 年 8 月,从EventBridge 的文档来看,它仅支持以下过滤器类型:

  • Prefix matching前缀匹配
  • Anything-but matching除了匹配之外的任何东西
  • Numeric matching数字匹配
  • IP address matching -Exists matching IP地址匹配-存在匹配

Why does EventBridge does not support Suffix filtering OR How I filter using Suffix when I use EventBridge?为什么 EventBridge 不支持后缀过滤或者我在使用 EventBridge 时如何使用后缀过滤?

My use case: If a file with particular extension added only then I would like the events to be created.我的用例:如果仅添加了具有特定扩展名的文件,那么我希望创建事件。 This is possible if I use S3 Events.如果我使用 S3 事件,这是可能的。 However we can not use EventBridge as rules doe not support suffix filtering.但是我们不能使用 EventBridge,因为规则不支持后缀过滤。

There are work arounds ie the consumers can ignore the messages but that seems to be the hack in my scenarios.有一些解决方法,即消费者可以忽略这些消息,但这似乎是我的场景中的 hack。

Today AWS released a much-awaited feature of content filtering by enhancing the existing capabilities of an event-driven system.今天,AWS 通过增强事件驱动系统的现有功能,发布了一项期待已久的内容过滤功能。

To answer your question, now I think you can use the feature of suffix matching for this particular use case.为了回答您的问题,现在我认为您可以针对此特定用例使用后缀匹配功能。

{
  "FileName": [ { "suffix": ".png" } ]
}

You can read more about it here.你可以在这里读更多关于它的内容。
https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-event-patterns-content-based-filtering.html#eb-filtering-suffix-matching https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-event-patterns-content-based-filtering.html#eb-filtering-suffix-matching

https://aws.amazon.com/about-aws/whats-new/2022/11/amazon-eventbridge-enhanced-filtering-capabilities/ https://aws.amazon.com/about-aws/whats-new/2022/11/amazon-eventbridge-enhanced-filtering-capabilities/

For a temporary workaround, you can create an S3 bucket policy that restricts file upload to files with the desired file extension(s).对于临时解决方法,您可以创建一个 S3 存储桶策略,将文件上传限制为具有所需文件扩展名的文件。 In doing so, any file successfully uploaded to your bucket would conform to your file type requirements and trigger the notification.这样,任何成功上传到您的存储桶的文件都将符合您的文件类型要求并触发通知。

For example:例如:

{
"Version": "2012-10-17",
"Statement": [
    {
        "Sid": "",
        "Effect": "Allow",
        "Principal": {
            "AWS": "arn:aws:iam::YourAccountId:root"
        },
        "Action": "s3:PutObject",
        "Resource": [
            "arn:aws:s3:::YourS3Bucket/*.webm",
            "arn:aws:s3:::YourS3Bucket/*.wav",
            "arn:aws:s3:::YourS3Bucket/*.ogg",
            "arn:aws:s3:::YourS3Bucket/*.mp4",
            "arn:aws:s3:::YourS3Bucket/*.mp3",
            "arn:aws:s3:::YourS3Bucket/*.flac",
            "arn:aws:s3:::YourS3Bucket/*.amr"
        ]
    },
    {
        "Sid": "",
        "Effect": "Deny",
        "Principal": "*",
        "Action": "s3:PutObject",
        "NotResource": [
            "arn:aws:s3:::YourS3Bucket/*.webm",
            "arn:aws:s3:::YourS3Bucket/*.wav",
            "arn:aws:s3:::YourS3Bucket/*.ogg",
            "arn:aws:s3:::YourS3Bucket/*.mp4",
            "arn:aws:s3:::YourS3Bucket/*.mp3",
            "arn:aws:s3:::YourS3Bucket/*.flac",
            "arn:aws:s3:::YourS3Bucket/*.amr"
        ]
    }
]

} }

NOTE: The above policy would have an explicit deny.注意:上述策略将有一个明确的拒绝。 It is VERY important that you understand what your are writing in the policy or you could accidentally lock yourself out of your own bucket .了解您在保单中所写的内容非常重要,否则您可能会不小心将自己锁在自己的存储桶之外 (If you do, you can log in as root, delete the bucket policy and make the necessary edits) (如果这样做,您可以以 root 身份登录,删除存储桶策略并进行必要的编辑)

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

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