'How to exclude folder creation from triggering an AWS EventBridge rule?

I'd like to have an EventBridge rule that is triggered only when a file is uploaded into an S3 bucket, but I can't figure out how to specify the Event pattern that doesn't trigger the rule with the creation of a new folder inside the bucket. Every pattern I tried triggers the rule when a folder is created inside the bucket. This is the pattern I'm using:

{
  "detail-type": ["AWS API Call via CloudTrail"],
  "source": ["aws.s3"],
  "detail": {
    "eventSource": ["s3.amazonaws.com"],
    "requestParameters": {
      "bucketName": ["my-bucket"],
      "key": [{
        "prefix": "some-prefix"
      }]
    },
    "eventName": ["PutObject", "CompleteMultipartUpload", "CopyObject", "POST Object"]
  }
}

With this pattern, the rule is triggered both when a file is uploaded and a folder is created inside the bucket. Is there a way to solve this problem only by using the EventBridge rule?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source