在 Amazon Augmented AI 中使用 Amazon CloudWatch Events - Amazon SageMaker
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

在 Amazon Augmented AI 中使用 Amazon CloudWatch Events

当人工审核循环状态变为 CompletedFailedStopped 时,Amazon Augmented AI 使用 Amazon CloudWatch Events 提醒您。此事件传送保证至少进行一次,这意味着在人工循环结束后创建的所有事件都成功传送到 CloudWatch Events (Amazon EventBridge)。当审核循环状态变为其中之一时,Augmented AI 会向 CloudWatch Events 发送类似于如下所示的事件。

{ "version":"0", "id":"12345678-1111-2222-3333-12345EXAMPLE", "detail-type":"SageMaker A2I HumanLoop Status Change", "source":"aws.sagemaker", "account":"1111111111111", "time":"2019-11-14T17:49:25Z", "region":"us-east-1", "resources":["arn:aws:sagemaker:us-east-1:111111111111:human-loop/humanloop-nov-14-1"], "detail":{ "creationTime":"2019-11-14T17:37:36.740Z", "failureCode":null, "failureReason":null, "flowDefinitionArn":"arn:aws:sagemaker:us-east-1:111111111111:flow-definition/flowdef-nov-12", "humanLoopArn":"arn:aws:sagemaker:us-east-1:111111111111:human-loop/humanloop-nov-14-1", "humanLoopName":"humanloop-nov-14-1", "humanLoopOutput":{ "outputS3Uri":"s3://customer-output-bucket-specified-in-flow-definition/flowdef-nov-12/2019/11/14/17/37/36/humanloop-nov-14-1/output.json" }, "humanLoopStatus":"Completed" } }

JSON 输出中的详细信息包括以下内容:

creationTime

Augmented AI 创建人工循环时的时间戳。

failureCode

表示特定失败类型的失败代码。

failureReason

人工循环失败的原因。仅当人工审核循环状态为 failed 时,才会返回失败原因。

flowDefinitionArn

流定义的 Amazon 资源名称 (ARN) 或人工审核工作流

humanLoopArn

人工循环的 Amazon 资源名称 (ARN)。

humanLoopName

人工循环的名称。

humanLoopOutput

包含人工循环输出相关信息的对象。

outputS3Uri

Augmented AI 存储人工循环输出的 Amazon S3 对象的位置。

humanLoopStatus

人工循环的状态。

将事件从人工循环发送到 CloudWatch Events

要配置 CloudWatch Events 规则以获取状态更新或事件,对于您的 Amazon A2I 人类循环,请使用 Amazon Command Line Interface (Amazon CLI) put-rule命令。在使用 put-rule 命令时,请指定以下内容来接收人工循环状态:

  • \"source\":[\"aws.sagemaker\"]

  • \"detail-type\":[\"SageMaker A2I HumanLoop Status Change\"]

要配置 CloudWatch Events 规则以监控所有状态更改,请使用以下命令并替换占位符文本。例如,将 "A2IHumanLoopStatusChanges" 替换为唯一 CloudWatch Events 规则名称,并将 "arn:aws:iam::111122223333:role/MyRoleForThisRule" 替换为附加了 events.amazonaws.com 信任策略的 IAM 角色的 Amazon 资源名称 (ARN)。将 region 替换为您要在其中创建规则的 Amazon 区域。

aws events put-rule --name "A2IHumanLoopStatusChanges" --event-pattern "{\"source\":[\"aws.sagemaker\"],\"detail-type\":[\"SageMaker A2I HumanLoop Status Change\"]}" --role-arn "arn:aws:iam::111122223333:role/MyRoleForThisRule" --region "region"

要详细了解 put-rule 请求,请参阅《Amazon CloudWatch Events 用户指南》中的 CloudWatch Events 中的事件模式

设置目标以处理事件

要处理事件,您需要设置目标。例如,如果您想在人工循环状态更改时收到电子邮件,请使用《Amazon CloudWatch 用户指南》设置 Amazon SNS 通知的步骤来设置 Amazon SNS 主题,并在您的电子邮件中订阅。创建主题后,可以使用该主题创建目标。

将目标添加到 CloudWatch Events 规则
  1. 打开 CloudWatch 控制台:https://console.amazonaws.cn/cloudwatch/home

  2. 在导航窗格中,选择 Rules (规则)

  3. 选择要将目标添加到的规则。

  4. 选择 Actions,然后选择 Edit

  5. Targets (目标) 下,选择 Add Target (添加目标),然后选择要在检测到人工循环状态更改事件时使用的 Amazon 服务。

  6. 配置您的目标。有关说明,请参阅该服务的 Amazon 文档中有关配置目标的主题。

  7. 选择 Configure details (配置详细信息)

  8. 对于 Name (名称),输入一个名称并(可选)在 Description (描述) 中提供有关规则用途的详细信息。

  9. 请确保选中 State (状态) 旁边的复选框,以便您的规则以 Enabled (已启用) 状态列出。

  10. 选择 Update rule (更新规则)

使用人工审核输出

收到人工审核结果后,您可以分析结果并将其与机器学习预测进行比较。存储在 Amazon S3 存储桶中的 JSON 包含机器学习预测和人工审核结果。

更多信息

使用 Amazon EventBridge 自动执行 Amazon SageMaker