

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

# インスタンスの更新イベントとパターンの例
<a name="instance-refresh-eventbridge-events"></a>

Amazon EventBridge を使用すると、受信*イベント*を照合し、処理のために*ターゲット*にルーティングする*ルール*を作成できます。

**Topics**
+ [インスタンス更新イベント](#instance-refresh-events)
+ [ルートボリュームのライフサイクルイベントを置き換えるインスタンスの更新](#instance-refresh-rvr-lifecycle-events)

## インスタンス更新イベント
<a name="instance-refresh-events"></a>

次の例は、インスタンス更新機能のイベントを示しています。イベントは、ベストエフォートベースで生成されます。

**Topics**
+ [チェックポイントに達しました](#instance-refresh-checkpoint-reached)
+ [インスタンスの更新が開始されました](#instance-refresh-started)
+ [インスタンスの更新が成功しました](#instance-refresh-succeeded)
+ [インスタンスの更新に失敗しました](#instance-refresh-failed)
+ [インスタンスの更新がキャンセルされました](#instance-refresh-cancelled)
+ [インスタンス更新のロールバックが開始されました](#instance-refresh-rollback-started)
+ [インスタンスの更新のロールバックが成功しました](#instance-refresh-rollback-succeeded)
+ [インスタンスの更新のロールバックが失敗しました](#instance-refresh-rollback-failed)

### チェックポイントに達しました
<a name="instance-refresh-checkpoint-reached"></a>

置き換えられたインスタンスの数が、チェックポイントに定義された割合のしきい値に達すると、Amazon EC2 Auto Scaling は次のイベントを送信します。

```
{
  "version": "0",
  "id": "{{12345678}}-{{1234}}-{{1234}}-{{1234}}-{{123456789012}}",
  "detail-type": "EC2 Auto Scaling Instance Refresh Checkpoint Reached",
  "source": "aws.autoscaling",
  "account": "{{123456789012}}",
  "time": "{{yyyy}}-{{mm}}-{{dd}}T{{hh}}:{{mm}}:{{ss}}Z",
  "region": "{{us-west-2}}",
  "resources": [
    "{{auto-scaling-group-arn}}"
  ],
  "detail": {
    "InstanceRefreshId": "{{ab00cf8f}}-{{9126}}-{{4f3c}}-{{8010}}-{{dbb8cad6fb86}}",
    "AutoScalingGroupName": "{{my-asg}}",
    "CheckpointPercentage": "{{50}}",
    "CheckpointDelay": "{{300}}"
  }
}
```

### インスタンスの更新が開始されました
<a name="instance-refresh-started"></a>

インスタンスの更新のステータスが `InProgress` に変わると、Amazon EC2 Auto Scaling は次のイベントを送信します。

```
{
  "version": "0",
  "id": "{{12345678}}-{{1234}}-{{1234}}-{{1234}}-{{123456789012}}",
  "detail-type": "EC2 Auto Scaling Instance Refresh Started",
  "source": "aws.autoscaling",
  "account": "{{123456789012}}",
  "time": "{{yyyy}}-{{mm}}-{{dd}}T{{hh}}:{{mm}}:{{ss}}Z",
  "region": "{{us-west-2}}",
  "resources": [
    "{{auto-scaling-group-arn}}"
  ],
  "detail": {
    "InstanceRefreshId": "{{c613620e}}-{{07e2}}-{{4ed2}}-{{a9e2}}-{{ef8258911ade}}",
    "AutoScalingGroupName": "{{my-asg}}"
  }
}
```

### インスタンスの更新が成功しました
<a name="instance-refresh-succeeded"></a>

インスタンスの更新のステータスが `Successful` に変わると、Amazon EC2 Auto Scaling は次のイベントを送信します。

```
{
  "version": "0",
  "id": "{{12345678}}-{{1234}}-{{1234}}-{{1234}}-{{123456789012}}",
  "detail-type": "EC2 Auto Scaling Instance Refresh Succeeded",
  "source": "aws.autoscaling",
  "account": "{{123456789012}}",
  "time": "{{yyyy}}-{{mm}}-{{dd}}T{{hh}}:{{mm}}:{{ss}}Z",
  "region": "{{us-west-2}}",
  "resources": [
    "{{auto-scaling-group-arn}}"
  ],
  "detail": {
    "InstanceRefreshId": "{{c613620e}}-{{07e2}}-{{4ed2}}-{{a9e2}}-{{ef8258911ade}}",
    "AutoScalingGroupName": "{{my-asg}}"
  }
}
```

### インスタンスの更新に失敗しました
<a name="instance-refresh-failed"></a>

インスタンスの更新のステータスが `Failed` に変わると、Amazon EC2 Auto Scaling は次のイベントを送信します。

```
{
  "version": "0",
  "id": "{{12345678}}-{{1234}}-{{1234}}-{{1234}}-{{123456789012}}",
  "detail-type": "EC2 Auto Scaling Instance Refresh Failed",
  "source": "aws.autoscaling",
  "account": "{{123456789012}}",
  "time": "{{yyyy}}-{{mm}}-{{dd}}T{{hh}}:{{mm}}:{{ss}}Z",
  "region": "{{us-west-2}}",
  "resources": [
    "{{auto-scaling-group-arn}}"
  ],
  "detail": {
    "InstanceRefreshId": "{{c613620e}}-{{07e2}}-{{4ed2}}-{{a9e2}}-{{ef8258911ade}}",
    "AutoScalingGroupName": "{{my-asg}}"
  }
}
```

### インスタンスの更新がキャンセルされました
<a name="instance-refresh-cancelled"></a>

インスタンスの更新のステータスが `Cancelled` に変わると、Amazon EC2 Auto Scaling は次のイベントを送信します。

```
{
  "version": "0",
  "id": "{{12345678}}-{{1234}}-{{1234}}-{{1234}}-{{123456789012}}",
  "detail-type": "EC2 Auto Scaling Instance Refresh Cancelled",
  "source": "aws.autoscaling",
  "account": "{{123456789012}}",
  "time": "{{yyyy}}-{{mm}}-{{dd}}T{{hh}}:{{mm}}:{{ss}}Z",
  "region": "{{us-west-2}}",
  "resources": [
    "{{auto-scaling-group-arn}}"
  ],
  "detail": {
    "InstanceRefreshId": "{{c613620e}}-{{07e2}}-{{4ed2}}-{{a9e2}}-{{ef8258911ade}}",
    "AutoScalingGroupName": "{{my-asg}}"
  }
}
```

### インスタンス更新のロールバックが開始されました
<a name="instance-refresh-rollback-started"></a>

インスタンスの更新のステータスが `RollbackInProgress` に変わると、Amazon EC2 Auto Scaling は次のイベントを送信します。

```
{
  "version": "0",
  "id": "{{12345678}}-{{1234}}-{{1234}}-{{1234}}-{{123456789012}}",
  "detail-type": "EC2 Auto Scaling Instance Refresh Rollback Started",
  "source": "aws.autoscaling",
  "account": "{{123456789012}}",
  "time": "{{yyyy}}-{{mm}}-{{dd}}T{{hh}}:{{mm}}:{{ss}}Z",
  "region": "{{us-west-2}}",
  "resources": [
    "{{auto-scaling-group-arn}}"
  ],
  "detail": {
    "InstanceRefreshId": "{{c613620e}}-{{07e2}}-{{4ed2}}-{{a9e2}}-{{ef8258911ade}}",
    "AutoScalingGroupName": "{{my-asg}}"
  }
}
```

### インスタンスの更新のロールバックが成功しました
<a name="instance-refresh-rollback-succeeded"></a>

インスタンスの更新のステータスが `RollbackSuccessful` に変わると、Amazon EC2 Auto Scaling は次のイベントを送信します。

```
{
  "version": "0",
  "id": "{{12345678}}-{{1234}}-{{1234}}-{{1234}}-{{123456789012}}",
  "detail-type": "EC2 Auto Scaling Instance Refresh Rollback Succeeded",
  "source": "aws.autoscaling",
  "account": "{{123456789012}}",
  "time": "{{yyyy}}-{{mm}}-{{dd}}T{{hh}}:{{mm}}:{{ss}}Z",
  "region": "{{us-west-2}}",
  "resources": [
    "{{auto-scaling-group-arn}}"
  ],
  "detail": {
    "InstanceRefreshId": "{{c613620e}}-{{07e2}}-{{4ed2}}-{{a9e2}}-{{ef8258911ade}}",
    "AutoScalingGroupName": "{{my-asg}}"
  }
}
```

### インスタンスの更新のロールバックが失敗しました
<a name="instance-refresh-rollback-failed"></a>

インスタンスの更新のステータスが `Failed` に変わると、Amazon EC2 Auto Scaling は次のイベントを送信します。

```
{
  "version": "0",
  "id": "{{12345678}}-{{1234}}-{{1234}}-{{1234}}-{{123456789012}}",
  "detail-type": "EC2 Auto Scaling Instance Refresh Rollback Failed",
  "source": "aws.autoscaling",
  "account": "{{123456789012}}",
  "time": "{{yyyy}}-{{mm}}-{{dd}}T{{hh}}:{{mm}}:{{ss}}Z",
  "region": "{{us-west-2}}",
  "resources": [
    "{{auto-scaling-group-arn}}"
  ],
  "detail": {
    "InstanceRefreshId": "{{c613620e}}-{{07e2}}-{{4ed2}}-{{a9e2}}-{{ef8258911ade}}",
    "AutoScalingGroupName": "{{my-asg}}"
  }
}
```

## ルートボリュームのライフサイクルイベントを置き換えるインスタンスの更新
<a name="instance-refresh-rvr-lifecycle-events"></a>

Auto Scaling グループにライフサイクルフックを追加すると、インスタンスが待機状態に移行するときに、Amazon EC2 Auto Scaling が EventBridge にイベントを送信します。詳細については、「[ルートボリュームを置き換えるライフサイクルフックを使用する](replace-root-volume.md#replace-root-volume-lifecycle-hooks)」を参照してください。

次の例は、Auto Scaling グループにインスタンスの更新中にルートボリュームの置き換えが行われているインスタンスがある場合のイベントを示しています。イベントは、ベストエフォートベースで出力されます。

**Topics**
+ [ルートボリュームのライフサイクルの置き換えアクションを開始する](#rvr-start-lifecycle-action)
+ [ルートボリュームのライフサイクルの置き換えアクションを終了する](#rvr-end-lifecycle-action)
+ [イベントパターンの例](#rvr-event-patterns)

### ルートボリュームのライフサイクルの置き換えアクションを開始する
<a name="rvr-start-lifecycle-action"></a>

インスタンスの更新中にルートボリュームの置き換えにインスタンスが選択され、その状態が に変わる場合`ReplacingRootVolume:Wait`。

```
{
  "version": "0",
  "id": "{{12345678}}-{{1234}}-{{1234}}-{{1234}}-{{123456789012}}",
  "detail-type": "EC2 Instance-terminate Lifecycle Action",
  "source": "aws.autoscaling",
  "account": "{{123456789012}}",
  "time": "{{2021}}-{{01}}-{{13}}T{{00}}:{{12}}:{{37}}.{{214}}Z",
  "region": "{{us-west-2}}",
  "resources": [
    "{{auto-scaling-group-arn}}"
  ],
  "detail": {
    "LifecycleActionToken": "{{71514b9d}}-{{6a40}}-{{4b26}}-{{8523}}-{{05e7eEXAMPLE}}",
    "AutoScalingGroupName": "{{my-asg}}",
    "LifecycleHookName": "{{my-terminate-lifecycle-hook}}",
    "EC2InstanceId": "i-{{1234567890abcdef0}}",
    "LifecycleTransition": "autoscaling:EC2_INSTANCE_TERMINATING",
    "NotificationMetadata": "{{additional-info}}",
    "Origin": "AutoScalingGroup",
    "Destination": "AutoScalingGroup",
    "Action": "ReplaceRootVolume"
  }
}
```

### ルートボリュームのライフサイクルの置き換えアクションを終了する
<a name="rvr-end-lifecycle-action"></a>

インスタンスがルートボリュームの置き換えを完了し、その状態が に変わったとき`Pending:Wait`。

```
{
  "version": "0",
  "id": "{{12345678}}-{{1234}}-{{1234}}-{{1234}}-{{123456789012}}",
  "detail-type": "EC2 Instance-launch Lifecycle Action",
  "source": "aws.autoscaling",
  "account": "{{123456789012}}",
  "time": "{{2021}}-{{01}}-{{13}}T{{00}}:{{12}}:{{37}}.{{214}}Z",
  "region": "{{us-west-2}}",
  "resources": [
    "{{auto-scaling-group-arn}}"
  ],
  "detail": {
    "LifecycleActionToken": "{{71514b9d}}-{{6a40}}-{{4b26}}-{{8523}}-{{05e7eEXAMPLE}}",
    "AutoScalingGroupName": "{{my-asg}}",
    "LifecycleHookName": "{{my-launch-lifecycle-hook}}",
    "EC2InstanceId": "i-{{1234567890abcdef0}}",
    "LifecycleTransition": "autoscaling:EC2_INSTANCE_LAUNCHING",
    "NotificationMetadata": "{{additional-info}}",
    "Origin": "AutoScalingGroup",
    "Destination": "AutoScalingGroup",
    "Action": "ReplaceRootVolume"
  }
}
```

### イベントパターンの例
<a name="rvr-event-patterns"></a>

前のセクションでは、ルートボリュームの置き換え戦略によるインスタンスの更新中に Amazon EC2 Auto Scaling によって出力されるイベントの例を示します。EventBridge イベントパターンは、一致するイベントと同じ構造をしています。イベントのパターンでは、照合する対象のフィールドを引用符で囲み、検出したい値を指定します。イベント内の次のフィールドは、ルールで定義され、アクションをトリガーするイベントパターンを形成します。

`"source": "aws.autoscaling"`  
イベントが Amazon EC2 Auto Scaling Group からのものであることを特定します。

`"detail-type": "{{EC2 Instance-launch Lifecycle Action}}"`  
イベントタイプを特定します。

`"Action": "{{ReplaceRootVolume}}"`  
インスタンスで実行されているアクションを識別します。

次のサンプルイベントパターンを使用して、ルートボリュームを置き換える準備をしているインスタンスに関連付けられているすべてのイベントをキャプチャします。

```
{
  "source": [ "aws.autoscaling" ],
  "detail-type": [ "EC2 Instance-terminate Lifecycle Action" ],
  "detail": {
      "Action": [ "ReplaceRootVolume" ]
   }
}
```

次のサンプルイベントパターンを使用して、ルートボリュームの置き換えが完了した後にサービスに戻るインスタンスに関連付けられているすべてのイベントをキャプチャします。

```
{
  "source": [ "aws.autoscaling" ],
  "detail-type": [ "EC2 Instance-launch Lifecycle Action" ],
  "detail": {
      "Action": [ "ReplaceRootVolume" ]
   }
}
```