

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 管理 Amazon DocumentDB 事件
<a name="managing-events"></a>

Amazon DocumentDB （具有 MongoDB 相容性） 會保留與叢集、執行個體、快照、安全群組和叢集參數群組相關的事件記錄。該資訊會包含事件的日期和時間、事件的來源名稱和來源類型，以及與事件相關的訊息。

**重要**  
對於某些管理功能，Amazon DocumentDB 使用與 Amazon RDS 和 Amazon Neptune 共用的操作技術。區域限制、區域層級受管的限制，會在 Amazon DocumentDB、Amazon RDS 和 Amazon Neptune 之間共用。如需詳細資訊，請參閱[區域配額](limits.md#limits-regional_quotas)。

**Topics**
+ [檢視 Amazon DocumentDB 事件類別](#viewing-event-categories)
+ [檢視 Amazon DocumentDB 事件](#viewing-events)

## 檢視 Amazon DocumentDB 事件類別
<a name="viewing-event-categories"></a>

每個 Amazon DocumentDB 資源類型都有與其相關聯的特定事件類型。您可以使用 AWS CLI `describe-event-categories`操作來檢視事件類型和 Amazon DocumentDB 資源類型之間的映射。

**參數**
+ **--source-type**- 選用。使用 `--source-type` 參數查看特定來源類型的事件類別。以下是允許值：
  + `db-cluster`
  + `db-instance`
  + `db-parameter-group`
  + `db-security-group`
  + `db-cluster-snapshot`
+ **--filters**- 選用。若要僅檢視 Amazon DocumentDB 的事件類別，請使用篩選條件 `--filter Name=engine,Values=docdb`。

**Example**  
以下程式碼會列出與叢集關聯的事件類別。  
若為 Linux、macOS 或 Unix：  

```
aws docdb describe-event-categories \
    --filter Name=engine,Values=docdb \
    --source-type db-cluster
```
針對 Windows：  

```
aws docdb describe-event-categories ^
    --filter Name=engine,Values=docdb ^
    --source-type db-cluster
```
此操作的輸出將會如下所示 (JSON 格式)。  

```
{
    "EventCategoriesMapList": [
        {
            "EventCategories": [
                "notification",
                "failure",
                "maintenance",
                "failover"
            ],
            "SourceType": "db-cluster"
        }
    ]
}
```
下列程式碼列出與每個 Amazon DocumentDB 來源類型相關聯的事件類別。  

```
aws docdb describe-event-categories
```
此操作的輸出將會如下所示 (JSON 格式)。  

```
{
    "EventCategoriesMapList": [
        {
            "SourceType": "db-instance",
            "EventCategories": [
                "notification",
                "failure",
                "creation",
                "maintenance",
                "deletion",
                "recovery",
                "restoration",
                "configuration change",
                "read replica",
                "backtrack",
                "low storage",
                "backup",
                "availability",
                "failover"
            ]
        },
        {
            "SourceType": "db-security-group",
            "EventCategories": [
                "configuration change",
                "failure"
            ]
        },
        {
            "SourceType": "db-parameter-group",
            "EventCategories": [
                "configuration change"
            ]
        },
        {
            "SourceType": "db-cluster",
            "EventCategories": [
                "notification",
                "failure",
                "maintenance",
                "failover"
            ]
        },
        {
            "SourceType": "db-cluster-snapshot",
            "EventCategories": [
                "backup"
            ]
        }
    ]
}
```

## 檢視 Amazon DocumentDB 事件
<a name="viewing-events"></a>

您可以透過 Amazon DocumentDB 主控台擷取 Amazon DocumentDB 資源的事件，此主控台會顯示過去 24 小時內的事件。您也可以使用 [describe-events](https://docs.aws.amazon.com/cli/latest/reference/docdb/describe-events.html) AWS CLI 命令或 [DescribeEvents](https://docs.aws.amazon.com/documentdb/latest/developerguide/API_DescribeEvents.html) Amazon DocumentDB API 操作來擷取 Amazon DocumentDB 資源的事件。如果您使用 AWS CLI 或 Amazon DocumentDB API 來檢視事件，您可以擷取過去 14 天內的事件。

------
#### [ Using the AWS 管理主控台 ]

**檢視過去 24 小時的所有 Amazon DocumentDB 執行個體事件**

1. 登入 AWS 管理主控台，並在 https：//[https://console.aws.amazon.com/docdb](https://console.aws.amazon.com/docdb) 開啟 Amazon DocumentDB 主控台。

1. 在導覽窗格中，選擇 **Events** (事件)。可用的事件隨即會出現在清單中。

1. 使用 **Filter (篩選條件)** 清單可依類型篩選事件。在文字方塊中輸入期限，以進一步篩選結果。例如，下列螢幕擷取畫面顯示篩選*快照*事件的所有 Amazon DocumentDB 事件。  
![\[事件區段的螢幕擷取畫面，顯示篩選快照的事件。\]](http://docs.aws.amazon.com/zh_tw/documentdb/latest/developerguide/images/events-filtering.png)

------
#### [ Using the AWS CLI ]

**檢視過去 7 天的所有 Amazon DocumentDB 執行個體事件**  
您可以使用 `--duration` 參數設為 `10080`(10，080 分鐘） 執行 [describe-events](https://docs.aws.amazon.com/cli/latest/reference/docdb/describe-events.html) AWS CLI 操作，以檢視過去 7 天內的所有 Amazon DocumentDB 執行個體事件。

```
aws docdb describe-events --duration 10080
```

**篩選 Amazon DocumentDB 事件**

若要查看特定 Amazon DocumentDB 事件，請使用 `describe-events`操作搭配下列參數。

**參數**
+ **--filter**- 需要將傳回的值限制為 Amazon DocumentDB 事件。使用 **Name=engine,Values=docdb** 僅篩選 Amazon DocumentDB 的所有事件。
+ **--source-identifier**- 選用。要傳回其事件的事件來源識別碼。如果省略，則會傳回所有來源的事件。
+ **--source-type**- 選用，除非`--source-identifier`已提供，否則為必要項目。如果提供 `--source-identifier`，則 `--source-type` 必須和 `--source-identifier` 的類型一致。以下是允許值：
  + `db-cluster`
  + `db-instance`
  + `db-parameter-group`
  + `db-security-group`
  + `db-cluster-snapshot`

下列範例列出所有 Amazon DocumentDB 事件。

```
aws docdb describe-events --filters Name=engine,Values=docdb
```

此操作的輸出將會如下所示 (JSON 格式)。

```
{
    "Events": [
        {
            "SourceArn": "arn:aws:rds:us-east-1:123SAMPLE012:db:sample-cluster-instance3",
            "Message": "instance created",
            "SourceType": "db-instance",
            "Date": "2018-12-11T21:17:40.023Z",
            "SourceIdentifier": "sample-cluster-instance3",
            "EventCategories": [
                "creation"
            ]
        },
        {
            "SourceArn": "arn:aws:rds:us-east-1:123SAMPLE012:db:docdb-2018-12-11-21-08-23",
            "Message": "instance shutdown",
            "SourceType": "db-instance",
            "Date": "2018-12-11T21:25:01.245Z",
            "SourceIdentifier": "docdb-2018-12-11-21-08-23",
            "EventCategories": [
                "availability"
            ]
        },
        {
            "SourceArn": "arn:aws:rds:us-east-1:123SAMPLE012:db:docdb-2018-12-11-21-08-23",
            "Message": "instance restarted",
            "SourceType": "db-instance",
            "Date": "2018-12-11T21:25:11.441Z",
            "SourceIdentifier": "docdb-2018-12-11-21-08-23",
            "EventCategories": [
                "availability"
            ]
        }
    ]
}
```

------

如需詳細資訊，請參閱[稽核 Amazon DocumentDB 事件](event-auditing.md)。