

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 将 AWS 用户通知与成本异常检测结合使用
<a name="cad-user-notifications"></a>

您可以使用 [AWS 用户通知服务](https://docs.aws.amazon.com/notifications/latest/userguide/what-is-service.html)来设置交付渠道，以获得有关成本异常检测事件的通知。当事件与指定的规则匹配时，您会收到通知。您可以通过多种渠道接收事件通知，包括电子邮件、[聊天应用程序（例如 Amazon Chime、Microsoft Teams 和 Slack）中的 Amazon Q 开发者版](https://docs.aws.amazon.com/chatbot/latest/adminguide/what-is.html)或 [AWS 控制台移动应用程序](https://docs.aws.amazon.com/consolemobileapp/latest/userguide/what-is-consolemobileapp.html)推送通知。您还可以使用 AWS 用户通知[控制台中的控制台通知中心](https://console.aws.amazon.com/notifications/)查看通知。

AWS 用户通知还支持聚合，这可以减少您在特定事件期间收到的通知数量。有关更多信息，请参阅《[AWS 用户通知服务用户指南](https://docs.aws.amazon.com/notifications/latest/userguide/what-is-service.html)》。

要使用 AWS 用户通知，您必须拥有正确的 AWS 身份和访问管理 (IAM) 权限。有关配置 IAM 权限的更多信息，请参阅《AWS 用户通知服务用户指南》**中的 [Creating a notification configuration](https://docs.aws.amazon.com/notifications/latest/userguide/getting-started.html#getting-started-step1)。

## 示例： EventBridge 的事件 `Anomaly Detected`
<a name="cad-user-notifications-example"></a>

以下是`Anomaly Detected`的通用示例事件。您可以使用 AWS 用户通知订阅 EventBridge 事件（例如此事件）。

```
{
    "version": "0",
    "id": "<id>", // alphanumeric string
    "source": "aws.ce",
    "detail-type": "Anomaly Detected",
    "account": "<account ID>", // 12 digit account id.
    "region": "<region>", // Cost Anomaly Detection home region.
    "time": "<date>", // Format: yyyy-MM-dd'T'hh:mm:ssZ
    "resources": [ 
         "arn:aws:ce::123456789012:anomalymonitor/abcdef12-1234-4ea0-84cc-918a97d736ef"
    ],
    "detail": {
         "accountName": "<account name>",
         "anomalyEndDate": "2021-05-25T00:00:00Z",
         "anomalyId": "12345678-abcd-ef12-3456-987654321a12",
         "anomalyScore": { 
            "currentScore": 0.47,
            "maxScore": 0.47
         },
         "anomalyStartDate": "2021-05-25T00:00:00Z",
         "dimensionValue": "<dimension value>", // service name for AWS Service Monitor
         "feedback": "string",
         "impact": {
            "maxImpact": 151,
            "totalActualSpend": 1301,
            "totalExpectedSpend": 300,
            "totalImpact": 1001,
            "totalImpactPercentage": 333.67
         },
         "rootCauses": [ 
            {
                "linkedAccount": "<linked account ID>", // 12 digit account id.
                "linkedAccountName": "<linked account name>",
                "region": "<region>",
                "service": "<service name>", // AWS service name
                "usageType": "<usage type>", // AWS service usage type
                "impact": {
                    "contribution": 601,
                }
            }
        ],
        "accountId": "<account ID>", // 12 digit account id.
        "monitorArn": "arn:aws:ce::123456789012:anomalymonitor/abcdef12-1234-4ea0-84cc-918a97d736ef",
        "monitorName": "<your monitor name>",
        "anomalyDetailsLink": "https://console.aws.amazon.com/cost-management/home#/anomaly-detection/monitors/abcdef12-1234-4ea0-84cc-918a97d736ef/anomalies/12345678-abcd-ef12-3456-987654321a12"
    }
}
```

## 筛选事件
<a name="cad-user-notifications-filter"></a>

您可以使用 AWS 用户通知控制台中提供的过滤器按服务和名称筛选事件，或者如果您根据 JSON 代码创建自己的 EventBridge 过滤器，则可以按特定属性筛选事件。

**Topics**
+ [示例：按影响筛选](#example-filter-by-impact)
+ [示例：按服务维度筛选](#example-filter-by-service-dimension)
+ [示例：按成本分配标签筛选](#example-filter-by-cost-allocation-tag)
+ [示例：按区域根本原因筛选](#example-filter-by-region-root-cause)
+ [示例：按多个条件筛选](#example-filter-composition)

### 示例：按影响筛选
<a name="example-filter-by-impact"></a>

以下筛选条件会捕获总影响超过 100 美元且影响百分比超过 10% 的任何异常。

```
{
    "detail": {
        "impact": {
            "totalImpact": [{
                "numeric": [">", 100]
            }],
            "totalImpactPercentage": [{
                "numeric": [">", 10]
            }]
        }
    }
}
```

### 示例：按服务维度筛选
<a name="example-filter-by-service-dimension"></a>

以下筛选器捕获服务监控器检测到的 EC2 服务特有的异常。 AWS 

```
{
    "detail": {
        "dimensionValue": ["Amazon Elastic Compute Cloud - Compute"],
        "monitorName": ["aws-services-monitor"]
    }
}
```

### 示例：按成本分配标签筛选
<a name="example-filter-by-cost-allocation-tag"></a>

以下筛选条件会捕获由维度成本分配标签监控检测到的前端应用程序团队的异常。

```
{
  "detail": {
    "dimensionValue": ["ApplicationTeam:Frontend"],
    "monitorName": ["dimensional-CAT-monitor"]
  }
}
```

### 示例：按区域根本原因筛选
<a name="example-filter-by-region-root-cause"></a>

以下筛选条件会捕获在美国东部（弗吉尼亚州北部）区域具有根本原因的异常。

```
{
  "detail": {
    "rootCauses": {
      "region": ["us-east-1"]
    }
  }
}
```

### 示例：按多个条件筛选
<a name="example-filter-composition"></a>

以下复杂的筛选条件会捕获总影响超过 100 美元、影响百分比超过 10% 并且根本原因位于美国东部（弗吉尼亚州北部）区域的前端应用程序团队的异常。

```
{
  "detail": {
    "dimensionValue": ["ApplicationTeam:Frontend"],
    "monitorName": ["dimensional-CAT-monitor"],
    "impact": {
        "totalImpact": [{ "numeric": [">", 100] }],
        "totalImpactPercentage": [{ "numeric": [">", 10] }]
    },
    "rootCauses": {
        "region": ["us-east-1"]
    }
  }
}
```