Create a rule in EventBridge to trigger the event of create object in S3 excluding a specific folder.

0

I have an Event Bridge rule so that whenever an object is created in an S3 bucket, the rule is triggered. However, I would like to exclude a particular folder. To meet this condition I have tried using https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-event-patterns-content-based-filtering.html#eb-filtering-suffix-matching Specifically, "Anything-but matching".

I am applying the following event pattern,

{
  "detail": {
    "bucket": {
      "name": ["backend-data"]
    },
    "object": {
      "key": [{
        "anything-but": "folder/*"
      }]
    }
  },
  "detail-type": ["Object Created"],
  "source": ["aws.s3"]
}

However it does not seem to have an effect, and does not exclude the folder. The problem is that it is not able to interpret "*". I have tried to test it with an event similar to the following,

{
  "version": "0",
  "id": "123",
  "detail-type": "Object Created",
  "source": "aws.s3",
  "account": "123",
  "time": "2024-02-19T11:03:42Z",
  "region": "us-east-1",
  "resources": ["arn:aws:s3:::backend-data"],
  "detail": {
    "version": "0",
    "bucket": {
      "name": "backend-data"
    },
    "object": {
      "key": "**folder/object.json.gz**",
      "size": 123,
      "etag": "asdf",
      "version-id": "asdf",
      "sequencer": "123"
    },
    "request-id": "ASDF",
    "requester": "12312",
    "source-ip-address": "123.0.0.0",
    "reason": "PutObject"
  }
}

And if I modify by the specific value, it works fine.

"key": [{
        "anything-but": "folder/object.json.gz"
  }]
Diego
asked 2 months ago209 views
1 Answer
0

I solved it using the conjunction of "anything-but" and "prefix", using the folder name as a prefix.

{
  "detail": {
    "bucket": {
      "name": ["backend-data"]
    },
    "object": {
      "key": [{
        "anything-but": {
          "prefix": "folder"
        }
      }]
    }
  },
  "detail-type": ["Object Created"],
  "source": ["aws.s3"]
}
Diego
answered 2 months ago
profile picture
EXPERT
reviewed 16 days ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions