

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

# 使用 Amazon EventBridge 事件跟踪屏幕录制状态
<a name="track-screen-recording-status"></a>

借助 Amazon EventBridge，您可以近乎实时地查看[代理屏幕录像](agent-screen-recording.md)的状态。每个代理屏幕录制的事件包括 success/failure 状态、带有描述的故障代码、录制位置、录制文件大小、已安装的客户端版本以及屏幕录制的开始和结束时间。

您可以与其他 AWS 服务集成，以获得代理屏幕录像的分析或监控见解：
+ 使用 A [mazon CloudWatch 日志见解](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/AnalyzingLogData.html)进行查询
+ 在 [Amazon Quick](https://aws.amazon.com/quicksight/) 控制面板中获取近乎实时的提醒
+ 在 Amazon Connect 之外创建汇总报告
+ 将您的其他自定义数据管道解决方案与 Amazon 连接起来 EventBridge

**Topics**
+ [Amazon EventBridge 事件负载格式](#eventbridge-payload-formats)
+ [创建规则以匹配 Amazon EventBridge 事件](#create-eventbridge-rule)
+ [配置已创建的 Amazon EventBridge 规则的目标](#configure-eventbridge-target)

## Amazon EventBridge 事件负载格式
<a name="eventbridge-payload-formats"></a>

### 带有屏幕录制状态的事件-已启动
<a name="event-initiated"></a>

当代理接受联系人时（可能是在录制开始之前），对于启用代理屏幕录制的每一次接触，都会触发此事件。

```
{  
  "version": "0",  
  "id": "the_event_id_from_eventbridge",  
  "detail-type": "Screen Recording Status Changed",  
  "source": "aws.connect",  
  "account": "your_aws_account_id",  
  "time": "2026-01-01T00:00:00Z",  
  "region": "us-west-2",  
  "resources": [  
    "arn:aws:connect:us-west-2:your_aws_account_id:instance/your_instance_id/contact/your_contact_id",  
    "arn:aws:connect:us-west-2:your_aws_account_id:instance/your_instance_id"  
  ],  
  "detail": {  
    "version": "1.0",  
    "recordingStatus": "INITIATED",  
    "eventDeduplicationId": "unique_uuid",  
    "instanceArn": "arn:aws:connect:us-west-2:your_aws_account_id:instance/your_instance_id",  
    "contactArn": "arn:aws:connect:us-west-2:your_aws_account_id:instance/your_instance_id/contact/your_contact_id",  
    "agentArn": "arn:aws:connect:us-west-2:your_aws_account_id:instance/your_instance_id/agent/your_agent_id",  
    "clientInfo": {  
      "appVersion": "2.0.3.0",  
    }  
  }  
}
```

### 显示屏幕录制状态的事件-已完成
<a name="event-completed"></a>

当屏幕录制在代理桌面上结束时，会触发此事件。这并不意味着屏幕录像已成功上传到您的 Amazon S3 存储桶。

```
{  
  "version": "0",  
  "id": "the_event_id_from_eventbridge",  
  "detail-type": "Screen Recording Status Changed",  
  "source": "aws.connect",  
  "account": "your_aws_account_id",  
  "time": "2026-01-01T00:00:00Z",  
  "region": "us-west-2",  
  "resources": [  
    "arn:aws:connect:us-west-2:your_aws_account_id:instance/your_instance_id/contact/your_contact_id",  
    "arn:aws:connect:us-west-2:your_aws_account_id:instance/your_instance_id"  
  ],  
  "detail": {  
    "version": "1.0",  
    "recordingStatus": "COMPLETED",  
    "eventDeduplicationId": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeee",  
    "instanceArn": "arn:aws:connect:us-west-2:your_aws_account_id:instance/your_instance_id",  
    "contactArn": "arn:aws:connect:us-west-2:your_aws_account_id:instance/your_instance_id/contact/your_contact_id",  
    "agentArn": "arn:aws:connect:us-west-2:your_aws_account_id:instance/your_instance_id/agent/your_agent_id",  
    "clientInfo": {  
      "appVersion": "2.0.3.0",  
    },  
    "recordingInfo": {  
      "startTime": "2026-01-01T00:00:00.000Z",  
      "endTime": "2026-01-01T00:00:00.000Z",  
    }  
  }  
}
```

### 带有屏幕录制状态的事件-已发布
<a name="event-published"></a>

当屏幕录像成功上传到您的 Amazon S3 存储桶时，就会触发此事件。详细信息包括 Amazon S3 存储桶的位置、录制大小和录制时长。

```
{  
  "version": "0",  
  "id": "the_event_id_from_eventbridge",  
  "detail-type": "Screen Recording Status Changed",  
  "source": "aws.connect",  
  "account": "your_aws_account_id",  
  "time": "2026-01-01T00:00:00Z",  
  "region": "us-west-2",  
  "resources": [  
    "contactArn",  
    "instanceArn"  
  ],  
  "detail": {  
    "version": "1.0",  
    "recordingStatus": "PUBLISHED",  
    "eventDeduplicationId": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeee",  
    "instanceArn": "arn:aws:connect:us-west-2:your_aws_account_id:instance/your_instance_id",  
    "contactArn": "arn:aws:connect:us-west-2:your_aws_account_id:instance/your_instance_id/contact/your_contact_id",  
    "agentArn": "arn:aws:connect:us-west-2:your_aws_account_id:instance/your_instance_id/agent/your_agent_id",  
    "clientInfo": {  
      "appVersion": "2.0.3.0",  
    },  
    "recordingInfo": {  
      "startTime": "2026-01-01T00:00:00.000Z",  
      "endTime": "2026-01-01T00:00:00.000Z",  
      "publishTime": "2026-01-01T00:00:00.000Z",  
      "location": "s3://your-bucket-name/object-prefix/object-key",  
      "durationInMillis": 100000,  
      "sizeInBytes": 1000000  
    }  
  }  
}
```

### 显示屏幕录制状态的事件-失败
<a name="event-failed"></a>

如果屏幕录制失败，则会发出此事件。有关故障信息的详细信息是为了尽最大努力估计我们能够检测到的可能的故障原因。

```
{  
  "version": "0",  
  "id": "the_event_id_from_eventbridge",  
  "detail-type": "Screen Recording Status Changed",  
  "source": "aws.connect",  
  "account": "your_aws_account_id",  
  "time": "2026-01-01T00:00:00Z",  
  "region": "us-west-2",  
  "resources": [  
    "arn:aws:connect:us-west-2:your_aws_account_id:instance/your_instance_id/contact/cccccccc-cccc-cccc-cccc-ccccccccccccc",  
    "arn:aws:connect:us-west-2:your_aws_account_id:instance/your_instance_id"  
  ],  
  "detail": {  
    "version": "1.0",  
    "recordingStatus": "FAILED",  
    "eventDeduplicationId": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeee",  
    "instanceArn": "arn:aws:connect:us-west-2:your_aws_account_id:instance/your_instance_id",  
    "contactArn": "arn:aws:connect:us-west-2:your_aws_account_id:instance/your_instance_id/contact/cccccccc-cccc-cccc-cccc-ccccccccccccc",  
    "agentArn": "arn:aws:connect:us-west-2:your_aws_account_id:instance/your_instance_id/agent/your_agent_id",  
    "clientInfo": {  
      "appVersion": "2.0.3.0",  
    },  
    "failureInfo": {  
      "code": "UNKNOWN",  
      "message": "UNKNOWN",  
      "source": "Unknown failure"  
    },  
    "recordingInfo": {  
      "startTime": "2026-01-01T00:00:00.000Z"  
    }  
  }  
}
```

## 创建规则以匹配 Amazon EventBridge 事件
<a name="create-eventbridge-rule"></a>

要订阅 Amazon EventBridge 事件以获取屏幕录制状态，您需要创建一个与定义的事件源和事件详细信息类型相匹配的 Amazon EventBridge 规则。这可以通过 AWS 控制台或 AWS CDK 库来实现。

### 使用 AWS 控制台创建规则
<a name="create-rule-console"></a>

在 AWS 控制台中，在 Amazon EventBridge → 总线 → 规则中创建新规则。

#### 使用默认事件总线
<a name="use-default-event-bus"></a>

![\[“创建规则” 页面显示了默认的事件总线选择。\]](http://docs.aws.amazon.com/zh_cn/connect/latest/adminguide/images/screen-recording-eventbridge-event-rule.png)


#### 使用模板事件模式
<a name="use-template-event-pattern"></a>

从下拉列表中选择已定义的事件模式。

![\[显示 aws.connect 的事件源下拉列表已选中。\]](http://docs.aws.amazon.com/zh_cn/connect/latest/adminguide/images/screen-recording-eventbridge-event-source.png)


![\[显示屏幕录制状态已更改的事件模式已选中。\]](http://docs.aws.amazon.com/zh_cn/connect/latest/adminguide/images/screen-recording-eventbridge-event-pattern.png)


如果事件类型未显示在下拉列表中，则也可以使用**自定义模式（JSON 编辑器）创建相同的模式**：

```
{  
  "source": [ "aws.connect" ],  
  "detailType": [ "Screen Recording Status Changed" ]  
}
```

### 使用创建规则 AWS CDK
<a name="create-rule-cdk"></a>

或者，如果您使用管理 AWS 资源 AWS CDK，则以下是构建 Amazon EventBridge 规则的示例 TypeScript 代码片段：

```
import { Rule } from 'aws-cdk-lib/aws-events';  
  
const eventBridgeRule = new Rule(this, 'YourEventBridgeRuleLogicalName', {  
    ruleName: 'your-event-bridge-rule-name',  
    description: 'your rule description',  
    eventPattern: {  
        source: [ "aws.connect" ],  
        detailType: [ "Screen Recording Status Changed" ]  
    }  
});
```

## 配置已创建的 Amazon EventBridge 规则的目标
<a name="configure-eventbridge-target"></a>

Amazon EventBridge 支持将多项 AWS 服务作为目标。根据您的需求，您可以灵活地使用其他 AWS 服务构建自己的事件处理管道。您最多可以为每条规则定义五个目标。有关更多信息，请参阅《[亚马逊* EventBridge 用户指南》中的亚马逊 EventBridge *目标](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-targets.html)。

### CloudWatch 以 Amazon 日志组为示例目标
<a name="cloudwatch-log-group-target"></a>

以下示例使用 A [mazon CloudWatch 日志组](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/Working-with-log-groups-and-streams.html)作为目标。

![\[显示所选 CloudWatch 日志组的目标配置。\]](http://docs.aws.amazon.com/zh_cn/connect/latest/adminguide/images/screen-recording-eventbridge-target-cwl.png)


在 AWS CDK 代码中，创建资源并将其添加到 Amazon EventBridge 规则中：

```
import { LogGroup, RetentionDays } from "aws-cdk-lib/aws-logs";  
import { CloudWatchLogGroup } from 'aws-cdk-lib/aws-events-targets';  
   
const logGroup = new LogGroup(this, 'YourLogGroupLogicalName', {  
    logGroupName: '"/aws/events/your-log-group-name',  
    retention: RetentionDays.ONE_YEAR  
});  
  
eventBridgeRule.addTarget(new CloudWatchLogGroup((logGroup)));
```

#### Amazon CloudWatch 日志见解查询示例
<a name="cloudwatch-log-insights-queries"></a>

以下是一些使用 Amazon CloudWatch Insights 查询语言的查询示例：
+ **成功率查询示例**

  ```
  fields @timestamp, @message, detail  
  | stats sum(detail.recordingStatus= "PUBLISHED") as Count_Success,   
    sum(detail.recordingStatus= "INITIATED") as Count_Total,   
    Count_Success / Count_Total as Success_Ratio
  ```
+ **获取每个录制状态计数的示例查询**

  ```
  fields @timestamp, @message, detail  
  | stats count(*) as Count group by detail.recordingStatus as recordingStatus
  ```
+ **带有最常见故障代码的失败联系人查询示例**

  ```
  fields @timestamp, @message, detail  
  | filter detail.recordingStatus = "FAILED"   
  | stats count(*) as Count group by detail.failureInfo.code as FailureCode  
  | sort by Count desc
  ```
+ **联系失败次数最多的代理的查询示例**

  ```
  fields @timestamp, @message, detail  
  | filter detail.recordingStatus = "FAILED"   
  | stats count(*) as Count group by detail.agentArn as AgentArn  
  | sort by Count desc
  ```