Search code examples
amazon-web-servicesaws-event-bridge

AWS Event bridge rule pattern to capture event without wildcards use


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"
        }
      ]
}

Solution

  • 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