

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# Amazon Augmented AI Amazon CloudWatch Events で を使用する
<a name="a2i-cloudwatch-events"></a>

Amazon Augmented AI は人間によるレビューループのステータスが `Completed`、`Failed`、または `Stopped` に変わると Amazon CloudWatch Events を使用してアラートを送信します。このイベント配信は少なくとも 1 回保証されます。つまり、作成されたすべてのイベントはヒューマンループの終了時に 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 にイベントを送信する
<a name="a2i-cloud-watch-events-rule-setup"></a>

Amazon A2I ヒューマンループのステータス更新または*イベント*を取得するように CloudWatch Events ルールを設定するには、 AWS Command Line Interface (AWS CLI) [https://docs.aws.amazon.com/cli/latest/reference/events/put-rule.html](https://docs.aws.amazon.com/cli/latest/reference/events/put-rule.html) コマンドを使用します。`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* を、ルールを作成する AWS リージョンに置き換えます。

```
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 のイベントパターン](https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/CloudWatchEventsandEventPatterns.html)」を参照してください。

## イベントを処理するターゲットを設定する
<a name="a2i-subscribe-cloud-watch-events"></a>

イベントを処理するには、ターゲットを設定する必要があります。例えば、ヒューマンループのステータス変更時に E メールを受信する場合は、*Amazon CloudWatch ユーザーガイド*の「[Amazon SNS 通知の設定](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/US_SetupSNS.html)」に記載されている手順を使用して Amazon SNS トピックを設定し、E メールでそれをサブスクライブします。トピックを作成したら、このトピックを使用してターゲットを作成できます。

**CloudWatch Events ルールにターゲットを追加するには**

1. CloudWatch コンソール [https://console.aws.amazon.com/cloudwatch/home](https://console.aws.amazon.com/cloudwatch/home) を開きます。

1. ナビゲーションペインで **[ルール]** を選択します。

1. ターゲットを追加するルールを選択します。

1. **[アクション]** を選択し、**[編集]** を選択します。

1. **ターゲット** で、**ターゲットの追加** を選択し、ヒューマンループステータス変更イベントが検出されたときに実行する AWS サービスを選択します。

1. ターゲットを設定します。手順については、[そのサービスのAWS ドキュメント](https://docs.aws.amazon.com/index.html)のターゲット設定に関するトピックを参照してください。

1. [**詳細の設定**] を選択します。

1. **[名前]** に名前を入力し、必要に応じて [**説明**] にルールの目的の詳細を入力します。

1. **[State]** (状態) のチェックボックスをオンにして、ルールが **[Enabled]** (有効) として表示されることを確認します。

1. [**ルールの更新**] を選択します。

## ヒューマンレビューの出力の使用
<a name="using-human-review-output"></a>

ヒューマンレビューの結果を受け取ったら、結果を分析し、機械学習の予測と比較することができます。Amazon S3 バケットに格納される JSON には、機械学習の予測と人間によるレビューの結果の両方が含まれます。

## 詳細情報
<a name="amazon-augmented-ai-programmatic-walkthroughs"></a>

[Amazon SageMaker AI が Amazon EventBridge に送信するイベント](automating-sagemaker-with-eventbridge.md)