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"
  }]
1개 답변
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
답변함 3달 전
profile picture
전문가
검토됨 한 달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠