amazon-web-servicesamazon-s3amazon-cloudwatchaws-event-bridgeamazon-cloudtrail

How to trigger an AWS Event Rule when a S3 key with a specific suffix gets uploaded


I'm trying to create an AWS Event Rule that is only triggered when a file with a specific suffix is uploaded to an S3 bucket.

{
  "source": [
    "aws.s3"
  ],
  "detail-type": [
    "AWS API Call via CloudTrail"
  ],
  "detail": {
    "eventSource": [
      "s3.amazonaws.com"
    ],
    "eventName": [
      "PutObject",
      "CompleteMultipartUpload"
    ],
    "requestParameters": {
      "bucketName": [
        "bucket-name"
      ],
      "key": [
        { "suffix": ".csv" }
      ]
    }
  }
}

As I understand there AWS has content-based filtering which can be used but docs doesn't show the ability to use a suffix, only prefix among other patterns: https://docs.aws.amazon.com/eventbridge/latest/userguide/content-filtering-with-event-patterns.html

Ideally I could be able to do it here without the need for an intermediary Lambda as my event target is an ECS Fargate task.


Solution

  • It appears that suffix matching has been added

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

    Therefore, the example given in the question is now valid!