

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

# 使用 CloudWatch 事件监控 Amazon EBS 快照存档
<a name="monitor-snapshot-archiving"></a>

Amazon EBS 发出与快照归档操作相关的事件。您可以使用 AWS Lambda 和 Amazon CloudWatch Events 以编程方式处理事件通知。尽最大努力发出事件。有关更多信息，请参阅 [Amazon EventBridge 用户指南](https://docs.aws.amazon.com/eventbridge/latest/userguide/)。

提供的事件如下：
+ `archiveSnapshot` – 当快照归档操作成功或失败时发出。

  以下是在快照归档操作成功时发送事件的示例。

  ```
  {
     "version": "0",
     "id": "01234567-0123-0123-0123-012345678901",
     "detail-type": "EBS Snapshot Notification",
     "source": "aws.ec2",
     "account": "123456789012",
     "time": "2021-05-25T13:12:22Z",
     "region": "us-east-1",
     "resources": [
       "arn:aws:ec2:us-east-1::snapshot/snap-01234567890abcdef"
     ],
     "detail": {
       "event": "archiveSnapshot",
       "result": "succeeded",
       "cause": "",
       "request-id": "123456789",
       "snapshot_id": "arn:aws:ec2:us-east-1::snapshot/snap-01234567890abcdef",
       "startTime": "2021-05-25T13:12:22Z",
       "endTime": "2021-05-45T15:30:00Z",
       "recycleBinExitTime": "2021-10-45T15:30:00Z"
    }
  ```

  以下是在快照归档操作失败时发送事件的示例。

  ```
  {
     "version": "0",
    "id": "01234567-0123-0123-0123-012345678901",
    "detail-type": "EBS Snapshot Notification",
    "source": "aws.ec2",
    "account": "123456789012",
    "time": "2021-05-25T13:12:22Z",
    "region": "us-east-1",
    "resources": [
      "arn:aws:ec2:us-east-1::snapshot/snap-01234567890abcdef"
    ],
    "detail": {
      "event": "archiveSnapshot",
      "result": "failed",
      "cause": "Source snapshot ID is not valid",
      "request-id": "1234567890",
      "snapshot_id": "arn:aws:ec2:us-east-1::snapshot/snap-01234567890abcdef",
      "startTime": "2021-05-25T13:12:22Z",
      "endTime": "2021-05-45T15:30:00Z",
      "recycleBinExitTime": "2021-10-45T15:30:00Z"
    }
  }
  ```
+ `permanentRestoreSnapshot` – 当永久还原操作成功或失败时发出。

  以下是在快照还原操作成功时发送事件的示例。

  ```
  {
     "version": "0",
    "id": "01234567-0123-0123-0123-012345678901",
    "detail-type": "EBS Snapshot Notification",
    "source": "aws.ec2",
    "account": "123456789012",
    "time": "2021-05-25T13:12:22Z",
    "region": "us-east-1",
    "resources": [
      "arn:aws:ec2:us-east-1::snapshot/snap-01234567890abcdef"
    ],
    "detail": {
      "event": "permanentRestoreSnapshot",
      "result": "succeeded",
      "cause": "",
      "request-id": "1234567890",
      "snapshot_id": "arn:aws:ec2:us-east-1::snapshot/snap-01234567890abcdef",
      "startTime": "2021-05-25T13:12:22Z",
      "endTime": "2021-10-45T15:30:00Z"
    }
  }
  ```

  以下是在永久还原操作失败时发送事件的示例。

  ```
  {
     "version": "0",
    "id": "01234567-0123-0123-0123-012345678901",
    "detail-type": "EBS Snapshot Notification",
    "source": "aws.ec2",
    "account": "123456789012",
    "time": "2021-05-25T13:12:22Z",
    "region": "us-east-1",
    "resources": [
      "arn:aws:ec2:us-east-1::snapshot/snap-01234567890abcdef"
    ],
    "detail": {
      "event": "permanentRestoreSnapshot",
      "result": "failed",
      "cause": "Source snapshot ID is not valid",
      "request-id": "1234567890",
      "snapshot_id": "arn:aws:ec2:us-east-1::snapshot/snap-01234567890abcdef",
      "startTime": "2021-05-25T13:12:22Z",
      "endTime": "2021-05-45T15:30:00Z",
      "recycleBinExitTime": "2021-10-45T15:30:00Z"
    }
  }
  ```
+ `temporaryRestoreSnapshot` – 当临时还原操作成功或失败时发出。

  以下是在快照暂时还原操作成功时发送事件的示例。

  ```
  {
     "version": "0",
    "id": "01234567-0123-0123-0123-012345678901",
    "detail-type": "EBS Snapshot Notification",
    "source": "aws.ec2",
    "account": "123456789012",
    "time": "2021-05-25T13:12:22Z",
    "region": "us-east-1",
    "resources": [
      "arn:aws:ec2:us-east-1::snapshot/snap-01234567890abcdef"
    ],
    "detail": {
      "event": "temporaryRestoreSnapshot",
      "result": "succeeded",
      "cause": "",
      "request-id": "1234567890",
      "snapshot_id": "arn:aws:ec2:us-us-east-1::snapshot/snap-01234567890abcdef",
      "startTime": "2021-05-25T13:12:22Z",
      "endTime": "2021-05-45T15:30:00Z",    
      "restoreExpiryTime": "2021-06-45T15:30:00Z",
      "recycleBinExitTime": "2021-10-45T15:30:00Z"
    }
  }
  ```

  下面是在临时还原操作失败时发送事件的示例。

  ```
  {
     "version": "0",
    "id": "01234567-0123-0123-0123-012345678901",
    "detail-type": "EBS Snapshot Notification",
    "source": "aws.ec2",
    "account": "123456789012",
    "time": "2021-05-25T13:12:22Z",
    "region": "us-east-1",
    "resources": [
      "arn:aws:ec2:us-east-1::snapshot/snap-01234567890abcdef"
    ],
    "detail": {
      "event": "temporaryRestoreSnapshot",
      "result": "failed",
      "cause": "Source snapshot ID is not valid",
      "request-id": "1234567890",
      "snapshot_id": "arn:aws:ec2:us-east-1::snapshot/snap-01234567890abcdef",
      "startTime": "2021-05-25T13:12:22Z",
      "endTime": "2021-05-45T15:30:00Z",
      "recycleBinExitTime": "2021-10-45T15:30:00Z"
    }
  }
  ```
+ `restoreExpiry` – 在临时还原快照的还原期到期时触发。

  示例如下：

  ```
  {
     "version": "0",
    "id": "01234567-0123-0123-0123-012345678901",
    "detail-type": "EBS Snapshot Notification",
    "source": "aws.ec2",
    "account": "123456789012",
    "time": "2021-05-25T13:12:22Z",
    "region": "us-east-1",
    "resources": [
      "arn:aws:ec2:us-east-1::snapshot/snap-01234567890abcdef"
    ],
    "detail": {
      "event": "restoryExpiry",
      "result": "succeeded",
      "cause": "",
      "request-id": "1234567890",
      "snapshot_id": "arn:aws:ec2:us-east-1::snapshot/snap-01234567890abcdef",
      "startTime": "2021-05-25T13:12:22Z",
      "endTime": "2021-05-45T15:30:00Z",
      "recycleBinExitTime": "2021-10-45T15:30:00Z"
    }
  }
  ```