首页 > 解决方案 > 如何在 Cloudwatch Events 上使用正则表达式

问题描述

在 Cloudwatch Event 中,我们可以编写关于源、详细信息等的过滤规则。我目前的做法如下所示,

  DefaultEventsRule:
    Type: AWS::Events::Rule
    Properties:
      Name: "CloudWatchRule1"
      Description: "Match events and send them to corresponding queue for delivery."
      EventPattern:
        {
          "source": ["xyz"],
          "resources":
              ...

是否可以对其进行正则表达式操作source?看起来不可能在事件上编写正则表达式;SO中还有另一个问题问类似的问题(for destination),解决方法是使用单独的规则,似乎这也是source的唯一方法。

参考:regex-in-cloudwatch-event-pattern-matching

标签: regexamazon-web-serviceseventsfilteramazon-cloudwatch

解决方案


截至目前,不支持正则表达式。您可以做的最大工作是使用complex filter查看EventBridge 详细信息content-filtering-with-event-patterns

另请参阅此 SO 问题中的答案,regex-in-cloudwatch-event-pattern-matching对我有帮助。

希望AWSRegEx matching的家伙将来会添加!


推荐阅读