

• Amazon Systems Manager CloudWatch 控制面板在 2026 年 4 月 30 日之后将不再可用。客户可以像现在一样继续使用 Amazon CloudWatch 控制台来查看、创建和管理其 Amazon CloudWatch 控制面板。有关更多信息，请参阅 [Amazon CloudWatch 控制面板文档](https://docs.amazonaws.cn/AmazonCloudWatch/latest/monitoring/CloudWatch_Dashboards.html)。

# 手动创建 OpsItems（Amazon CLI）
<a name="OpsCenter-creating-OpsItems-CLI"></a>

以下过程介绍了使用 Amazon Command Line Interface (Amazon CLI) 创建 OpsItem 的方法。

**使用 Amazon CLI 创建 OpsItem**

1. 安装并配置 Amazon Command Line Interface（Amazon CLI）（如果尚未执行该操作）。

   有关信息，请参阅[安装或更新 Amazon CLI 的最新版本](https://docs.amazonaws.cn/cli/latest/userguide/getting-started-install.html)。

1. 打开 Amazon 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 格式参数的信息，请参阅 *Amazon Command Line Interface 用户指南*中的[在 Amazon CLI 中将引号和字符串结合使用](https://docs.amazonaws.cn/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` 文档指定为相关联的自动化运行手册的 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` 键创建将 `Amazon-RestartEC2Instance` 运行手册指定为相关联的自动化运行手册的 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\"}}
```