5

How can I match a CloudWatch event on a regex. I need to invoke only a particular SNS target on a specific job name. e.g, something like below where I want to do a regex match on TranscriptionJobName. Thanks.

{
  "source": [
    "aws.transcribe"
  ],
  "detail-type": [
    "Transcribe Job State Change"
  ],
  "detail": {
    "TranscriptionJobStatus": [
      "COMPLETED",
      "FAILED"
    ],
    "TranscriptionJobName": [
      "transcription-localhost-*"
    ]
  }
}
ctc
  • 2,640
  • 1
  • 16
  • 18
user4848830
  • 779
  • 12
  • 22

4 Answers4

3

This is now possible with EventBridge and its ability to do prefix matching. This works for me. I have a Lambda function set up as a target, and the function is executed only upon a Transcribe job reaching COMPLETED status and having a job name starting with voicemail-.

{
  "source": [
    "aws.transcribe"
  ],
  "detail": {
    "TranscriptionJobName": [
      {
        "prefix": "voicemail-"
      }
    ],
    "TranscriptionJobStatus": [
      "COMPLETED"
    ]
  }
}
ctc
  • 2,640
  • 1
  • 16
  • 18
1

I ended up creating separate rule for each target SNS topic.

user4848830
  • 779
  • 12
  • 22
1

I'm trying to solve this as well and it does not appear this is possible, given the following AWS documentation.

https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/CloudWatchEventsandEventPatterns.html

It is important to remember the following about event pattern matching:

  • For a pattern to match an event, the event must contain all the field names listed in the pattern. The field names must appear in the event with the same nesting structure.

  • Other fields of the event not mentioned in the pattern are ignored; effectively, there is a "": "" wildcard for fields not mentioned.

  • The matching is exact (character-by-character), without case-folding or any other string normalization.

  • The values being matched follow JSON rules: Strings enclosed in quotes, numbers, and the unquoted keywords true, false, and null.

  • Number matching is at the string representation level. For example, 300, 300.0, and 3.0e2 are not considered equal.

Bummer...

Brooks
  • 7,099
  • 6
  • 51
  • 82
0

I have figured this out by using Numeric matching expression in the event pattern for Guard Duty findings something like below;

    {
      "detail": {
        "severity": [{
          "numeric": [">", 0, "<=", 8.9]
        }]
      },
      "detail-type": [
        "GuardDuty Finding"
      ],
      "source": [
        "aws.guardduty"
      ]
    }
Asaph
  • 159,146
  • 25
  • 197
  • 199
Sagar Jadhav
  • 385
  • 1
  • 5
  • 15