

• 2026 年 4 月 30 日之後， AWS Systems Manager CloudWatch Dashboard 將不再可用。客戶可以繼續使用 Amazon CloudWatch 主控台來檢視、建立和管理其 Amazon CloudWatch 儀表板，就像現在一樣。如需詳細資訊，請參閱 [Amazon CloudWatch Dashboard 文件](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Dashboards.html)。

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

# 建立 OpsItems
<a name="OpsCenter-create-OpsItems"></a>

設定 OpsCenter (AWS Systems Manager 中的工具) 並將其與您的 AWS 服務整合之後，您的 AWS 服務會根據預設規則、事件或警示自動建立 OpsItems。

您可以檢視預設 Amazon EventBridge 規則的狀態和嚴重性等級。如果需要，您可以在 Amazon EventBridge 中建立或編輯這些規則。您也可以在 Amazon CloudWatch 中檢視警示，並建立或編輯警示。您可以使用規則和警示來設定事件，以便為事件自動產生 OpsItems。

系統建立 OpsItem 後，它會處於**待處理**狀態。開始調查 OpsItem 後，您可以將狀態變更為**進行中**，在修復 OpsItem 之後可以將狀態變更為**已解決**。如需有關如何在 AWS 服務 中設定警示和規則以建立 OpsItems 和如何手動建立 OpsItems 的詳細資訊，請參閱下列主題。

**Topics**
+ [設定 EventBridge 規則以建立 OpsItems](OpsCenter-automatically-create-OpsItems-2.md)
+ [設定 CloudWatch 警示以建立 OpsItems](OpsCenter-create-OpsItems-from-CloudWatch-Alarms.md)
+ [手動建立 OpsItems](OpsCenter-manually-create-OpsItems.md)

# 設定 EventBridge 規則以建立 OpsItems
<a name="OpsCenter-automatically-create-OpsItems-2"></a>

Amazon EventBridge 收到事件後，它會根據預設規則建立新的 OpsItem。您可以建立規則或編輯現有的規則，以將 OpsCenter 設定為 EventBridge 事件的目標。如需有關如何建立事件規則的詳細資訊，請參閱《Amazon EventBridge 使用者指南》**中的[為 AWS 服務建立規則](https://docs.aws.amazon.com/eventbridge/latest/userguide/create-eventbridge-rule.html)。

**設定 EventBridge 規則以在 OpsCenter 中建立 OpsItems**

1. 前往 [https://console.aws.amazon.com/events/](https://console.aws.amazon.com/events/) 開啟 Amazon EventBridge 主控台。

1. 在導覽窗格中，選擇**規則**。

1. 在 **Rules** (規則) 頁面，針對 **Event bus** (事件匯流排)，選擇 **default** (預設值)。

1. 在**規則**中，選取名稱旁的核取方塊，以選擇規則。

1. 選取規則的名稱，開啟其詳細資訊頁面。在**規則詳細資訊**中，確認**狀態**已設定為**已啟用**。
**注意**  
如有必要，您可以使用頁面右上角的**編輯**來更新狀態。

1. 選擇 **Targets (目標)** 標籤。

1. 在 **Targets (目標)** 索引標籤上，選擇 **Edit (編輯)**。

1. 對於**目標類型**，請選取 **AWS 服務**。

1. 針對 **Select a target** (選取目標)，請選擇 **Systems Manager OpsItem**。

1. 對於許多目標類型，EventBridge 需要許可才能將事件傳送到目標。在這些情況下，EventBridge 可以建立執行規則所需的 AWS Identity and Access Management (IAM) 角色：
   + 若要自動建立 IAM 角色，請選擇**為此特定資源建立新角色**。
   + 若要使用您建立的 IAM 角色授予 EventBridge 許可，以在 OpsCenter 中建立 OpsItems，請選擇 **Use existing role** (使用現有的角色)。

1. 在**其他設定**的**設定目標輸入**中，選擇**輸入轉換器**。

   您可以使用**輸入轉換器**選項，指定重複資料刪除字串和 OpsItems 的其他重要資訊，例如標題和嚴重性。

1. 選擇**設定輸入轉換器**。

1. 在**目標輸入轉換器**的**輸入路徑**中，指定針對觸發事件要剖析的值。例如，若要透過觸發規則的事件來剖析開始時間、結束時間和其他詳細資訊，請使用下列 JSON。

   ```
   {
       "end-time": "$.detail.EndTime",
       "failure-cause": "$.detail.cause",
       "resources": "$.resources[0]",
       "source": "$.detail.source",
       "start-time": "$.detail.StartTime"
   }
   ```

1. 針對 **Template** (範本)，指定要傳送至目標的資訊。例如，使用下列 JSON 將資訊傳遞至 OpsCenter。該資訊用於建立 OpsItem。
**注意**  
如果輸入範本為 JSON 格式，則範本中的物件值不能包含引號。例如，資源、失敗原因、來源、開始時間和結束時間的值不能加引號。

   ```
   {
       "title": "EBS snapshot copy failed",
       "description": "CloudWatch Event Rule SSMOpsItems-EBS-snapshot-copy-failed was triggered. Your EBS snapshot copy has failed. See below for more details.",
       "category": "Availability",
       "severity": "2",
       "source": "EC2",
       "operationalData": {
           "/aws/dedup": {
               "type": "SearchableString",
               "value": "{\"dedupString\":\"SSMOpsItems-EBS-snapshot-copy-failed\"}"
           },
           "/aws/automations": {
               "value": "[ { \"automationType\": \"AWS:SSM:Automation\", \"automationId\": \"AWS-CopySnapshot\" } ]"
           },
           "failure-cause": {
               "value": <failure-cause>
           },
           "source": {
               "value": <source>
           },
           "start-time": {
               "value": <start-time>
           },
           "end-time": {
               "value": <end-time>
           },
            },
           "resources": {
               "value": <resources>
           }
       }
   }
   ```

   如需這些欄位的詳細資訊，請參閱《*Amazon EventBridge 使用者指南*》中的[轉換目標輸入](https://docs.aws.amazon.com/eventbridge/latest/userguide/transform-input.html)。

1. 選擇**確認**。

1. 選擇**下一步**。

1. 選擇**下一步**。

1. 選擇**更新規則**。

從事件建立 OpsItem 之後，您就可以開啟 OpsItem 並向下捲動至 **Private operational data (私有營運資料)** 區段，檢視事件詳細資訊。如需如何在 OpsItem 中設定選項的資訊，請參閱 [管理 OpsItems](OpsCenter-working-with-OpsItems.md)。

# 設定 CloudWatch 警示以建立 OpsItems
<a name="OpsCenter-create-OpsItems-from-CloudWatch-Alarms"></a>

在 中OpsCenter工具 的整合設定期間 AWS Systems Manager，您可以讓 Amazon CloudWatch OpsItems 根據常見警示自動建立 。您可以建立警示，也可以編輯現有警示來在 OpsCenter 中建立 OpsItems。

當您設定警示以建立 時，CloudWatch 會在 AWS Identity and Access Management (IAM) 中建立新的服務連結角色OpsItems。新角色已命名為 `AWSServiceRoleForCloudWatchAlarms_ActionSSM`。如需有關 CloudWatch 服務連結角色的詳細資訊，請參閱《Amazon CloudWatch 使用者指南》**中的[使用 CloudWatch 的服務連結角色](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/using-service-linked-roles.html)。

CloudWatch 警示產生 OpsItem 後，OpsItem 會顯示 **CloudWatch 警示 - '*alarm\$1name*' 處於 ALARM 狀態**。

若要檢視特定 OpsItem 的詳細資訊，選擇 OpsItem，然後選擇**相關資源詳細資訊**索引標籤。您可以手動編輯 OpsItems 來變更詳細資訊，例如嚴重性或類別。不過，當您編輯警示的嚴重性或類別時，Systems Manager 無法更新已從警示建立之 OpsItems 的嚴重性或類別。如果警報建立了 OpsItem 而且如果您指定了重複資料刪除字串，則警示不會建立額外的 OpsItems，即使您在 CloudWatch 中編輯警示也是如此。如果 OpsItem 已在 OpsCenter 中解決，CloudWatch 將建立新的 OpsItem。

如需有關設定 CloudWatch 警示的詳細資訊，請參閱下列主題。

**Topics**
+ [設定 CloudWatch 警示以建立 OpsItems (主控台)](OpsCenter-creating-or-editing-existing-alarm-console.md)
+ [設定現有的 CloudWatch 警示以建立 OpsItems (以程式設計方式)](OpsCenter-configuring-an-existing-alarm-programmatically.md)

# 設定 CloudWatch 警示以建立 OpsItems (主控台)
<a name="OpsCenter-creating-or-editing-existing-alarm-console"></a>

您可以手動建立警示或更新現有警示，以便在 Amazon CloudWatch 中建立 OpsItems。

**建立 CloudWatch 警示並將 Systems Manager 設定為該警示的目標**

1. 完成《Amazon CloudWatch 使用者指南》**內[根據靜態閾值建立 CloudWatch 警示](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/ConsoleAlarms.html)中指定的步驟 1–9。

1. 在 **Systems Manager 動作**區段中，選擇**新增 Systems Manager OpsCenter 動作**。

1. 選擇 **OpsItems**。

1. 在**嚴重性**中，選擇 1 到 4。

1. (選用) 在**類別**中，選擇 OpsItem 的類別。

1. 完成《Amazon CloudWatch 使用者指南》**內[根據靜態閾值建立 CloudWatch 警示](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/ConsoleAlarms.html)中指定的步驟 11–13。

1. 選擇 **Next** (下一步) 並完成精靈。

**編輯現有的警示，並將 Systems Manager 設定為該警示的目標**

1. 透過 [https://console.aws.amazon.com/cloudwatch/](https://console.aws.amazon.com/cloudwatch/) 開啟 CloudWatch 主控台。

1. 在導覽窗格中，選擇 **Alarms** (警示)。

1. 選取警示，然後選擇 **Actions** (動作)、**Edit** (編輯)。

1. (選用) 變更 **Metrics** (指標) 和 **Conditions** (條件) 選項中的設定，然後選擇 **Next** (下一步)。

1. 在 **Systems Manager** (Systems Manager) 區段中，選擇 **Add Systems Manager OpsCenter action** (新增 Systems Manager OpsCenter 動作)。

1. 對於 **Severity** (嚴重性)，選擇數字。
**注意**  
嚴重性是使用者定義的值。您或您的組織會決定每個嚴重性值的含義，以及與每個嚴重性相關的任何服務水準協議。

1. (選用) 對於 **Category** (類別)，選擇一個選項。

1. 選擇 **Next** (下一步) 並完成精靈。

# 設定現有的 CloudWatch 警示以建立 OpsItems (以程式設計方式)
<a name="OpsCenter-configuring-an-existing-alarm-programmatically"></a>

您可以使用 AWS Command Line Interface (AWS CLI)、 AWS CloudFormation 範本或Java程式碼片段，設定 Amazon CloudWatch 警示以OpsItems程式設計方式建立 。

**Topics**
+ [開始之前](#OpsCenter-create-OpsItems-from-CloudWatch-Alarms-before-you-begin)
+ [設定 CloudWatch 警示以建立 OpsItems (AWS CLI)](#OpsCenter-create-OpsItems-from-CloudWatch-Alarms-manually-configure-cli)
+ [設定 CloudWatch 警示以建立或更新 OpsItems (CloudFormation)](#OpsCenter-create-OpsItems-from-CloudWatch-Alarms-programmatically-configure-CloudFormation)
+ [設定 CloudWatch 警示以建立或更新 OpsItems (Java)](#OpsCenter-create-OpsItems-from-CloudWatch-Alarms-programmatically-configure-java)

## 開始之前
<a name="OpsCenter-create-OpsItems-from-CloudWatch-Alarms-before-you-begin"></a>

如果以程式設計方式編輯現有的警示，或建立警示 (該警示會建立 OpsItems)，則您必須指定 Amazon Resource Name (ARN)。此 ARN 可識別 Systems Manager OpsCenter 作為從警示建立之 OpsItems 的目標。您可以自訂 ARN，以便從警示建立之 OpsItems 包含特定資訊，例如嚴重性或類別。每個 ARN 包含下表中所述的資訊。


****  

| 參數 | 詳細資訊 | 
| --- | --- | 
|  `Region` (必要)  |   AWS 區域 警示所在的 。例如：`us-west-2`。如需您可在其中使用 OpsCenter 之 AWS 區域 相關資訊，請參閱 [AWS Systems Manager 端點和配額](https://docs.aws.amazon.com/general/latest/gr/ssm.html)。  | 
|  `account_ID` (必要)  |  用來建立警示的相同 AWS 帳戶 ID。例如：`123456789012`。帳戶 ID 後面必須加上冒號 (`:`) 和參數 `opsitem`，如下列範例所示。  | 
|  `severity` (必要)  |  從警示建立之 OpsItems 的使用者定義嚴重性層級。有效值：`1`、`2`、`3`、`4`  | 
|  `Category` (選用)  |  從警示建立之 OpsItems 的類別 有效值：`Availability`、`Cost`、`Performance`、`Recovery` 和 `Security`。  | 

使用下列語法建立 ARN。此 ARN 不包含選用的 `Category` 參數。

```
arn:aws:ssm:Region:account_ID:opsitem:severity
```

以下是範例。

```
arn:aws:ssm:us-west-2:123456789012:opsitem:3
```

若要建立使用選用 `Category` 參數的 ARN，請使用下列語法。

```
arn:aws:ssm:Region:account_ID:opsitem:severity#CATEGORY=category_name
```

以下是範例。

```
arn:aws:ssm:us-west-2:123456789012:opsitem:3#CATEGORY=Security
```

## 設定 CloudWatch 警示以建立 OpsItems (AWS CLI)
<a name="OpsCenter-create-OpsItems-from-CloudWatch-Alarms-manually-configure-cli"></a>

此命令要求您為 `alarm-actions` 參數指定 ARN。如需如何建立 ARN 的相關資訊，請參閱 [開始之前](#OpsCenter-create-OpsItems-from-CloudWatch-Alarms-before-you-begin)。

**設定 CloudWatch 警示以建立 OpsItems (AWS CLI)**

1. 如果您尚未安裝並設定 AWS Command Line Interface (AWS CLI)，請安裝並設定 。

   如需相關資訊，請參閱[安裝或更新最新版本的 AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)。

1. 執行下列命令以收集您要設定之警示的相關資訊。

   ```
   aws cloudwatch describe-alarms --alarm-names "alarm name"
   ```

1. 執行下列命令以更新警示。將每個*範例資源預留位置*取代為您自己的資訊。

   ```
   aws cloudwatch put-metric-alarm --alarm-name name \
   --alarm-description "description" \
   --metric-name name --namespace namespace \
   --statistic statistic --period value --threshold value \
   --comparison-operator value \
   --dimensions "dimensions" --evaluation-periods value \
       --alarm-actions arn:aws:ssm:Region:account_ID:opsitem:severity#CATEGORY=category_name \
   --unit unit
   ```

   範例如下。

------
#### [ Linux & macOS ]

   ```
   aws cloudwatch put-metric-alarm --alarm-name cpu-mon \
   --alarm-description "Alarm when CPU exceeds 70 percent" \
   --metric-name CPUUtilization --namespace AWS/EC2 \
   --statistic Average --period 300 --threshold 70 \
   --comparison-operator GreaterThanThreshold \
   --dimensions "Name=InstanceId,Value=i-12345678" --evaluation-periods 2 \
   --alarm-actions arn:aws:ssm:us-east-1:123456789012:opsitem:3#CATEGORY=Security \
   --unit Percent
   ```

------
#### [ Windows ]

   ```
   aws cloudwatch put-metric-alarm --alarm-name cpu-mon ^
   --alarm-description "Alarm when CPU exceeds 70 percent" ^
   --metric-name CPUUtilization --namespace AWS/EC2 ^
   --statistic Average --period 300 --threshold 70 ^
   --comparison-operator GreaterThanThreshold ^
   --dimensions "Name=InstanceId,Value=i-12345678" --evaluation-periods 2 ^
   --alarm-actions arn:aws:ssm:us-east-1:123456789012:opsitem:3#CATEGORY=Security ^
   --unit Percent
   ```

------

## 設定 CloudWatch 警示以建立或更新 OpsItems (CloudFormation)
<a name="OpsCenter-create-OpsItems-from-CloudWatch-Alarms-programmatically-configure-CloudFormation"></a>

本節包含可用來設定 CloudWatch 警示以自動建立或更新 的 AWS CloudFormation 範本OpsItems。每個範本都要求您為 `AlarmActions` 參數指定 ARN。如需如何建立 ARN 的相關資訊，請參閱 [開始之前](#OpsCenter-create-OpsItems-from-CloudWatch-Alarms-before-you-begin)。

**指標警示** – 使用下列 CloudFormation 範本來建立或更新 CloudWatch 指標警示。此範本中指定的警示會監控 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體狀態檢查。如果警示進入 `ALARM` 狀態，它會在 OpsCenter 中建立 OpsItem。

```
    {
      "AWSTemplateFormatVersion": "2010-09-09",
      "Parameters" : {
        "RecoveryInstance" : {
          "Description" : "The EC2 instance ID to associate this alarm with.",
          "Type" : "AWS::EC2::Instance::Id"
        }
      },
      "Resources": {
        "RecoveryTestAlarm": {
          "Type": "AWS::CloudWatch::Alarm",
          "Properties": {
            "AlarmDescription": "Run a recovery action when instance status check fails for 15 consecutive minutes.",
            "Namespace": "AWS/EC2" ,
            "MetricName": "StatusCheckFailed_System",
            "Statistic": "Minimum",
            "Period": "60",
            "EvaluationPeriods": "15",
            "ComparisonOperator": "GreaterThanThreshold",
            "Threshold": "0",
            "AlarmActions": [ {"Fn::Join" : ["", ["arn:arn:aws:ssm:Region:account_ID:opsitem:severity#CATEGORY=category_name", { "Ref" : "AWS::Partition" }, ":ssm:", { "Ref" : "AWS::Region" }, { "Ref" : "AWS:: AccountId" }, ":opsitem:3" ]]} ],
            "Dimensions": [{"Name": "InstanceId","Value": {"Ref": "RecoveryInstance"}}]
          }
        }
      }
    }
```

**複合警示** – 使用下列 CloudFormation 範本來建立或更新複合警示。複合警示由多個指標警示組成。如果警示進入 `ALARM` 狀態，它會在 OpsCenter 中建立 OpsItem。

```
"Resources":{
       "HighResourceUsage":{
          "Type":"AWS::CloudWatch::CompositeAlarm",
          "Properties":{
             "AlarmName":"HighResourceUsage",
             "AlarmRule":"(ALARM(HighCPUUsage) OR ALARM(HighMemoryUsage)) AND NOT ALARM(DeploymentInProgress)",
             "AlarmActions":"arn:aws:ssm:Region:account_ID:opsitem:severity#CATEGORY=category_name",
             "AlarmDescription":"Indicates that the system resource usage is high while no known deployment is in progress"
          },
          "DependsOn":[
             "DeploymentInProgress",
             "HighCPUUsage",
             "HighMemoryUsage"
          ]
       },
       "DeploymentInProgress":{
          "Type":"AWS::CloudWatch::CompositeAlarm",
          "Properties":{
             "AlarmName":"DeploymentInProgress",
             "AlarmRule":"FALSE",
             "AlarmDescription":"Manually updated to TRUE/FALSE to disable other alarms"
          }
       },
       "HighCPUUsage":{
          "Type":"AWS::CloudWatch::Alarm",
          "Properties":{
             "AlarmDescription":"CPUusageishigh",
             "AlarmName":"HighCPUUsage",
             "ComparisonOperator":"GreaterThanThreshold",
             "EvaluationPeriods":1,
             "MetricName":"CPUUsage",
             "Namespace":"CustomNamespace",
             "Period":60,
             "Statistic":"Average",
             "Threshold":70,
             "TreatMissingData":"notBreaching"
          }
       },
       "HighMemoryUsage":{
          "Type":"AWS::CloudWatch::Alarm",
          "Properties":{
             "AlarmDescription":"Memoryusageishigh",
             "AlarmName":"HighMemoryUsage",
             "ComparisonOperator":"GreaterThanThreshold",
             "EvaluationPeriods":1,
             "MetricName":"MemoryUsage",
             "Namespace":"CustomNamespace",
             "Period":60,
             "Statistic":"Average",
             "Threshold":65,
             "TreatMissingData":"breaching"
          }
       }
    }
```

## 設定 CloudWatch 警示以建立或更新 OpsItems (Java)
<a name="OpsCenter-create-OpsItems-from-CloudWatch-Alarms-programmatically-configure-java"></a>

本節包含 Java 程式碼片段，您可以用這些程式碼片段來設定 CloudWatch 警示以自動建立或更新 OpsItems。每個程式碼片段都要求您為 `validSsmActionStr` 參數指定 ARN。如需如何建立 ARN 的相關資訊，請參閱 [開始之前](#OpsCenter-create-OpsItems-from-CloudWatch-Alarms-before-you-begin)。

**特定警示** – 使用以下 Java 程式碼片段來建立或更新 CloudWatch 警示。此範本中指定的警示會監控 Amazon EC2 執行個體狀態檢查。如果警示進入 `ALARM` 狀態，它會在 OpsCenter 中建立 OpsItem。

```
import com.amazonaws.services.cloudwatch.AmazonCloudWatch;
    import com.amazonaws.services.cloudwatch.AmazonCloudWatchClientBuilder;
    import com.amazonaws.services.cloudwatch.model.ComparisonOperator;
    import com.amazonaws.services.cloudwatch.model.Dimension;
    import com.amazonaws.services.cloudwatch.model.PutMetricAlarmRequest;
    import com.amazonaws.services.cloudwatch.model.PutMetricAlarmResult;
    import com.amazonaws.services.cloudwatch.model.StandardUnit;
    import com.amazonaws.services.cloudwatch.model.Statistic;
     
    private void putMetricAlarmWithSsmAction() {
        final AmazonCloudWatch cw =
                AmazonCloudWatchClientBuilder.defaultClient();
     
        Dimension dimension = new Dimension()
                .withName("InstanceId")
                .withValue(instanceId);
     
        String validSsmActionStr = "arn:aws:ssm:Region:account_ID:opsitem:severity#CATEGORY=category_name";
     
        PutMetricAlarmRequest request = new PutMetricAlarmRequest()
                .withAlarmName(alarmName)
                .withComparisonOperator(
                        ComparisonOperator.GreaterThanThreshold)
                .withEvaluationPeriods(1)
                .withMetricName("CPUUtilization")
                .withNamespace("AWS/EC2")
                .withPeriod(60)
                .withStatistic(Statistic.Average)
                .withThreshold(70.0)
                .withActionsEnabled(false)
                .withAlarmDescription(
                        "Alarm when server CPU utilization exceeds 70%")
                .withUnit(StandardUnit.Seconds)
                .withDimensions(dimension)
                .withAlarmActions(validSsmActionStr);
     
        PutMetricAlarmResult response = cw.putMetricAlarm(request);
    }
```

**更新所有警示** – 使用以下 Java 程式碼片段來更新 AWS 帳戶 中的所有 CloudWatch 警示，以在警示進入 `ALARM` 狀態時建立 OpsItems。

```
import com.amazonaws.services.cloudwatch.AmazonCloudWatch;
    import com.amazonaws.services.cloudwatch.AmazonCloudWatchClientBuilder;
    import com.amazonaws.services.cloudwatch.model.DescribeAlarmsRequest;
    import com.amazonaws.services.cloudwatch.model.DescribeAlarmsResult;
    import com.amazonaws.services.cloudwatch.model.MetricAlarm;
     
    private void listMetricAlarmsAndAddSsmAction() {
        final AmazonCloudWatch cw = AmazonCloudWatchClientBuilder.defaultClient();
     
        boolean done = false;
        DescribeAlarmsRequest request = new DescribeAlarmsRequest();
     
        String validSsmActionStr = "arn:aws:ssm:Region:account_ID:opsitem:severity#CATEGORY=category_name";
     
        while(!done) {
     
            DescribeAlarmsResult response = cw.describeAlarms(request);
     
            for(MetricAlarm alarm : response.getMetricAlarms()) {
                // assuming there are no alarm actions added for the metric alarm
                alarm.setAlarmActions(ImmutableList.of(validSsmActionStr));
            }
     
            request.setNextToken(response.getNextToken());
     
            if(response.getNextToken() == null) {
                done = true;
            }
        }
    }
```

# 手動建立 OpsItems
<a name="OpsCenter-manually-create-OpsItems"></a>

發現操作問題後，您可以在 OpsCenter (AWS Systems Manager 中的工具) 中手動建立 OpsItem，以管理並解決問題。

如果為 OpsCenter 設定了跨帳戶管理，Systems Manager 委派管理員或 AWS Organizations 管理帳戶可以為成員帳戶建立 OpsItems。如需更多詳細資訊，請參閱 [(選用) 手動設定 OpsCenter 以跨帳戶集中管理 OpsItems](OpsCenter-getting-started-multiple-accounts.md)。

您可以使用 AWS Systems Manager 主控台、AWS Command Line Interface (AWS CLI) 或 AWS Tools for Windows PowerShell 來建立 OpsItems。

**Topics**
+ [手動建立 OpsItems (主控台)](OpsCenter-creating-OpsItems-console.md)
+ [手動建立 OpsItems (AWS CLI)](OpsCenter-creating-OpsItems-CLI.md)
+ [手動建立 OpsItems (PowerShell)](OpsCenter-creating-OpsItems-Powershell.md)

# 手動建立 OpsItems (主控台)
<a name="OpsCenter-creating-OpsItems-console"></a>

 您可以使用 OpsItems AWS Systems Manager 主控台手動建立 。建立 OpsItem 後，它會顯示在您的 OpsCenter 帳戶中。如果為 OpsCenter 設定了跨帳戶管理，則 OpsCenter 會向委派管理員或管理帳戶提供為選定成員帳戶建立 OpsItems 的選項。如需詳細資訊，請參閱[(選用) 手動設定 OpsCenter 以跨帳戶集中管理 OpsItems](OpsCenter-getting-started-multiple-accounts.md)。

**OpsItem 使用 AWS Systems Manager 主控台建立**

1. 在 https：//[https://console.aws.amazon.com/systems-manager/](https://console.aws.amazon.com/systems-manager/) 開啟 AWS Systems Manager 主控台。

1. 在導覽窗格中，選擇 **OpsCenter**。

1. 選擇 **Create OpsItem** (建立 OpsItem)。如果您沒有看到此按鈕，請選擇 **OpsItems** 索引標籤，然後選擇 **Create OpsItem** (建立 OpsItem)。

1.  (選用) 選擇**其他帳戶**，然後選擇您要建立 OpsItem 的帳戶。
**注意**  
如果您要為會員帳戶建立 OpsItems，則需要執行此步驟。

1. 針對 **Title (標題)**，輸入描述名稱，協助您了解 OpsItem 的用途。

1. 對於 **Source** (來源)，輸入受影響的 AWS 資源類型或其他來源資訊，協助使用者了解 OpsItem 的根源。
**注意**  
建立 OpsItem 後，您不能編輯 **Source** (來源) 欄位。

1. (選用) 對於 **Priority** (優先順序)，選擇優先順序層級。

1. (選用) 對於 **Severity** (嚴重性)，選擇嚴重性層級。

1. (選用) 對於 **Category** (類別)，選擇類別。

1. 針對 **Description (描述)**，輸入此 OpsItem 的資訊，包括 (如合適) 重現問題的步驟。
**注意**  
主控台支援 OpsItem 描述欄位中的大多數 Markdown 格式。如需詳細資訊，請參閱《 AWS 管理主控台 入門指南》**中的[在主控台中使用 Markdown](https://docs.aws.amazon.com/awsconsolehelpdocs/latest/gsg/aws-markdown.html)。

1. 在**重複資料刪除字串**中，輸入系統可用來檢查重複 OpsItems 的單字。如需重複資料刪除字串的詳細資訊，請參閱[管理重複的 OpsItems](OpsCenter-working-deduplication.md)。

1. (選用) 在**通知**中，指定您希望 OpsItem 更新時發送通知的 Amazon SNS 主題的 Amazon Resource Name (ARN)。您必須指定與 相同的 AWS 區域 Amazon SNS ARNOpsItem。

1. (選用) 在**相關資源**中，選擇**新增**，指定受影響資源和任何相關資源的 ID 或 ARN。

1. 選擇**建立OpsItem**。

如果成功，頁面會顯示 OpsItem。委派管理員或管理帳戶為選取的成員帳戶建立 OpsItem 後，新 OpsItems 會顯示在管理員和成員帳戶的 OpsCenter 中。如需如何在 OpsItem 中設定選項的資訊，請參閱 [管理 OpsItems](OpsCenter-working-with-OpsItems.md)。

# 手動建立 OpsItems (AWS CLI)
<a name="OpsCenter-creating-OpsItems-CLI"></a>

下列處理程序說明如何使用 AWS Command Line Interface (AWS CLI) 建立 OpsItem。

**OpsItem 使用 建立 AWS CLI**

1. 如果您尚未安裝並設定 AWS Command Line Interface (AWS CLI)，請安裝並設定 。

   如需相關資訊，請參閱[安裝或更新最新版本的 AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)。

1. 開啟 AWS CLI 並執行下列命令來建立 OpsItem。將每個*範例資源預留位置*取代為您自己的資訊。

   ```
   aws ssm create-ops-item \
       --title "Descriptive_title" \
       --description "Information_about_the_issue" \
       --priority Number_between_1_and_5 \
       --source Source_of_the_issue \
       --operational-data Up_to_20_KB_of_data_or_path_to_JSON_file \
       --notifications Arn="SNS_ARN_in_same_Region" \
       --tags "Key=key_name,Value=a_value"
   ```

   **從檔案指定營運資料**

   當您建立 OpsItem 時，您可以從檔案指定營運資料。這個檔案必須是 JSON 檔案，且檔案內容必須使用以下格式。

   ```
   {
     "key_name": {
       "Type": "SearchableString",
       "Value": "Up to 20 KB of data"
     }
   }
   ```

   請見此處範例。

   ```
   aws ssm create-ops-item ^
       --title "EC2 instance disk full" ^
       --description "Log clean up may have failed which caused the disk to be full" ^
       --priority 2 ^
       --source ec2 ^
       --operational-data file:///Users/TestUser1/Desktop/OpsItems/opsData.json ^
       --notifications Arn="arn:aws:sns:us-west-1:12345678:TestUser1" ^
       --tags "Key=EC2,Value=Production"
   ```
**注意**  
如需如何在不同的本機作業系統的命令列輸入 JSON 格式參數的資訊，請參閱《*AWS Command Line Interface 使用者指南*》中的[在 AWS CLI中搭配字串使用引號](https://docs.aws.amazon.com/cli/latest/userguide/cli-usage-parameters-quoting-strings.html)。

   系統會傳回如下資訊。

   ```
   {
       "OpsItemId": "oi-1a2b3c4d5e6f"
   }
   ```

1. 執行以下命令來檢視您建立的 OpsItem 的詳細資訊。

   ```
   aws ssm get-ops-item --ops-item-id ID
   ```

   系統會傳回如下資訊。

   ```
   {
       "OpsItem": {
           "CreatedBy": "arn:aws:iam::12345678:user/TestUser",
           "CreatedTime": 1558386334.995,
           "Description": "Log clean up may have failed which caused the disk to be full",
           "LastModifiedBy": "arn:aws:iam::12345678:user/TestUser",
           "LastModifiedTime": 1558386334.995,
           "Notifications": [
               {
                   "Arn": "arn:aws:sns:us-west-1:12345678:TestUser"
               }
           ],
           "Priority": 2,
           "RelatedOpsItems": [],
           "Status": "Open",
           "OpsItemId": "oi-1a2b3c4d5e6f",
           "Title": "EC2 instance disk full",
           "Source": "ec2",
           "OperationalData": {
               "EC2": {
                   "Value": "12345",
                   "Type": "SearchableString"
               }
           }
       }
   }
   ```

1. 執行下列命令以更新 OpsItem。此命令會將狀態從 `Open` (預設值) 變更成 `InProgress`。

   ```
   aws ssm update-ops-item --ops-item-id ID --status InProgress
   ```

   此命令無輸出。

1. 再次執行以下命令，確認狀態是否已變更為 `InProgress`。

   ```
   aws ssm get-ops-item --ops-item-id ID
   ```

## 建立 OpsItem 的範例
<a name="OpsCenter_creating_OpsItems-CLI_examples"></a>

以下範例會說明如何使用 Linux 管理入口網站、macOS 或 Windows Server 建立 OpsItem。

**Linux 管理入口網站或 macOS**

以下命令會在 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體磁碟已滿時建立 OpsItem。

```
aws ssm create-ops-item \
    --title "EC2 instance disk full" \
    --description "Log clean up may have failed which caused the disk to be full" \
    --priority 2 \
    --source ec2 \
    --operational-data '{"EC2":{"Value":"12345","Type":"SearchableString"}}' \
    --notifications Arn="arn:aws:sns:us-west-1:12345678:TestUser1" \
    --tags "Key=EC2,Value=ProductionServers"
```

以下命令會在 `OperationalData` 中使用 `/aws/resources` 金鑰，來建立含 Amazon DynamoDB 相關資源的 OpsItem。

```
aws ssm create-ops-item \
    --title "EC2 instance disk full" \
    --description "Log clean up may have failed which caused the disk to be full" \
    --priority 2 \
    --source ec2 \
    --operational-data '{"/aws/resources":{"Value":"[{\"arn\": \"arn:aws:dynamodb:us-west-2:12345678:table/OpsItems\"}]","Type":"SearchableString"}}' \
    --notifications Arn="arn:aws:sns:us-west-2:12345678:TestUser"
```

以下命令會在 `OperationalData` 中使用 `/aws/automations` 金鑰，來建立可將 `AWS-ASGEnterStandby` 文件指定為相關聯的 Automation 執行手冊的 OpsItem。

```
aws ssm create-ops-item \
    --title "EC2 instance disk full" \
    --description "Log clean up may have failed which caused the disk to be full" \
    --priority 2 \
    --source ec2 \
    --operational-data '{"/aws/automations":{"Value":"[{\"automationId\": \"AWS-ASGEnterStandby\", \"automationType\": \"AWS::SSM::Automation\"}]","Type":"SearchableString"}}' \
    --notifications Arn="arn:aws:sns:us-west-2:12345678:TestUser"
```

**Windows**

以下命令會在 Amazon Relational Database Service (Amazon RDS) 執行個體未回應時建立 OpsItem。

```
aws ssm create-ops-item ^
    --title "RDS instance not responding" ^
    --description "RDS instance not responding to ping" ^
    --priority 1 ^
    --source RDS ^
    --operational-data={\"RDS\":{\"Value\":\"abcd\",\"Type\":\"SearchableString\"}} ^
    --notifications Arn="arn:aws:sns:us-west-1:12345678:TestUser1" ^
    --tags "Key=RDS,Value=ProductionServers"
```

以下命令會在 `OperationalData` 中使用 `/aws/resources` 金鑰，來建立含 Amazon EC2 執行個體相關資源的 OpsItem。

```
aws ssm create-ops-item ^
    --title "EC2 instance disk full" ^
    --description "Log clean up may have failed which caused the disk to be full" ^
    --priority 2 ^
    --source ec2 ^
    --operational-data={\"/aws/resources\":{\"Value\":\"[{\\"""arn\\""":\\"""arn:aws:ec2:us-east-1:123456789012:instance/i-1234567890abcdef0\\"""}]\",\"Type\":\"SearchableString\"}}
```

以下命令會在 `OperationalData` 中使用 `/aws/automations` 金鑰，來建立可將 `AWS-RestartEC2Instance` 執行手冊指定為相關聯的 Automation 執行手冊的 OpsItem。

```
aws ssm create-ops-item ^
    --title "EC2 instance disk full" ^
    --description "Log clean up may have failed which caused the disk to be full" ^
    --priority 2 ^
    --source ec2 ^
    --operational-data={\"/aws/automations\":{\"Value\":\"[{\\"""automationId\\""":\\"""AWS-RestartEC2Instance\\”"",\\"""automationType\\""":\\"""AWS::SSM::Automation\\"""}]\",\"Type\":\"SearchableString\"}}
```

# 手動建立 OpsItems (PowerShell)
<a name="OpsCenter-creating-OpsItems-Powershell"></a>

下列程序說明如何使用 AWS Tools for Windows PowerShell建立 OpsItem。

**OpsItem 使用 建立 AWS Tools for Windows PowerShell**

1. 開啟 AWS Tools for Windows PowerShell 並執行下列命令來指定您的登入資料。

   ```
   Set-AWSCredentials –AccessKey key-name –SecretKey key-name
   ```

1. 執行下列命令， AWS 區域 為您的PowerShell工作階段設定 。

   ```
   Set-DefaultAWSRegion -Region Region
   ```

1. 執行下列命令以建立新的 OpsItem。將每個*範例資源預留位置*取代為您自己的資訊。這個命令會指定 Systems Manager Automation Runbook 來修復此 OpsItem。

   ```
   $opsItem = New-Object Amazon.SimpleSystemsManagement.Model.OpsItemDataValue
   $opsItem.Type = [Amazon.SimpleSystemsManagement.OpsItemDataType]::SearchableString 
   $opsItem.Value = '[{\"automationId\":\"runbook_name\",\"automationType\":\"AWS::SSM::Automation\"}]'
   $newHash = @{" /aws/automations"=[Amazon.SimpleSystemsManagement.Model.OpsItemDataValue]$opsItem}
   
   New-SSMOpsItem `
       -Title "title" `
       -Description "description" `
       -Priority priority_number `
       -Source AWS_service `
       -OperationalData $newHash
   ```

   如果成功，命令會輸出新 OpsItem 的 ID。

以下範例指定受損 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體的 Amazon Resource Name (ARN)。

```
$opsItem = New-Object Amazon.SimpleSystemsManagement.Model.OpsItemDataValue
$opsItem.Type = [Amazon.SimpleSystemsManagement.OpsItemDataType]::SearchableString 
$opsItem.Value = '[{\"arn\":\"arn:aws:ec2:us-east-1:123456789012:instance/i-1234567890abcdef0\"}]'
$newHash = @{" /aws/resources"=[Amazon.SimpleSystemsManagement.Model.OpsItemDataValue]$opsItem}
New-SSMOpsItem -Title "EC2 instance disk full still" -Description "Log clean up may have failed which caused the disk to be full" -Priority 2 -Source ec2 -OperationalData $newHash
```