首页 > 解决方案 > 如何在 Cloudformation 中按用户名隔离事件

问题描述

我正在使用 Cloudformation 自动化 AWS Cloudwatch 事件。

我想按类型分离事件:root如果发生任何 root 活动,我们需要得到警报。

如何在 InputPathsMap 中编写代码

EventRule01:
    Type: AWS::Events::Rule
    Properties:
      Name: !Join
        - ""
        - - !GetAtt ResourceListAccountAlias.accountAlias
          - Root-Account-Change-Detected
      Description: "Triggers an alarm when AWS Root Account"
      State: "ENABLED"
      Targets:
        - Arn: !Ref AlarmNotificationTopic01
          Id: "001"
          InputTransformer:
            InputPathsMap:
              eventSource: "$.detail.eventSource"
              accountId: "$.detail.userIdentity.accountId"
              principalId: "$.detail.userIdentity.principalId"
              type: "$.detail.userIdentity"
              eventTime: "$.detail.eventTime"
              eventName: "$.detail.eventName"
            InputTemplate: |
              "The following event: <eventSource> was detected: <eventName> in account: <accountId>"

              "This event was initiated by: <principalId> for this Account: <type> on: <eventTime>"

      EventPattern:
        detail-type:
          - "AWS API Call via CloudTrail"
        detail:
          eventSource:
            - "signin.amazonaws.com"
          eventName:
            - "ConsoleLogin"

标签: amazon-web-servicesamazon-cloudformation

解决方案


InputPathsMap不是为了分离事件。所以你不能做你想做的事。您必须为不同的用户创建不同的规则,或者将所有事件定向到lambda 函数中。然后,该函数可以根据事件的主体进一步分发事件。


推荐阅读