skip to Main Content

I need help in creating a event bridge rule pattern to capture an AWS event given below, with few variables mentioned under angle brackets <>, requirement is to capture events where resources object ARN have suffix of sample AND prefix of product. The solution should not be using wildcards:

Event:

 {
      "requestParameters": {
        "bucketName": "mybucket",
        "key": "product/<2023-11-11>/<10-31-04>/<my->sample.json",
      },
      "resources": [
        {
          "type": "AWS::S3::Object",
          "ARN": "arn:aws:s3:::mybucket/product/<2023-11-11>/<10-31-04>/<my->sample.json"
        },
        {
          "accountId": "1234567890",
          "type": "AWS::S3::Bucket",
          "ARN": "arn:aws:s3:::mybucket"
        }
      ]
}

2

Answers


  1. You can use a pattern like this:

    {
      "resources": {
        "ARN": [{
          "wildcard": "arn:aws:s3:::*/product/*/*/*sample.*"
        }]
      }
    }
    

    In resources array, it will match any ARN that has the matching wildcard. The wildcard expects ARN to:

    1. start with arn:aws:s3:::
    2. can be any bucket
    3. the starting folder should be product
    4. It should have 2 folder
    5. the file name should end with sample

    Sample event of EventBridge

    {
      "id": "234234",
      "account": "23423423",
      "source": "asdfsf",
      "time": "2016-01-10T01:29:23Z",
      "region": "ap-south-1",
      "detail-type": "234234",
      "requestParameters": {
        "bucketName": "mybucket",
        "key": "product/2023-11-11/10-31-04/my-sample.json"
      },
      "resources": [{
          "type": "AWS::S3::Object",
          "ARN": "arn:aws:s3:::mybucket/product/2023-11-11/10-31-04/my-sample.json"
        },
        {
          "accountId": "1234567890",
          "type": "AWS::S3::Bucket",
          "ARN": "arn:aws:s3:::mybucket"
        }
      ]
    }
    

    References:

    https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-event-patterns-arrays.html

    Amazon EventBridge: Match an object inside of an array

    Login or Signup to reply.
  2. I’m not sure how you are getting events into the EventBridge, but I set up my S3 bucket to send events. Then I created the following rule and it works as expected:

    {
      "source": ["aws.s3"],
      "detail-type": ["Object Access Tier Changed", "Object ACL Updated", "Object Created", "Object Deleted", "Object Restore Completed", "Object Restore Expired", "Object Restore Initiated", "Object Storage Class Changed", "Object Tags Added", "Object Tags Deleted"],
      "detail": {
        "bucket": {
          "name": ["redacted-bucket-name"]
        },
        "object": {
          "key": [{"wildcard": "product/*/*/*sample.*"}]
        }
      }
    }
    

    The above works for any action, except GET.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search