手动创建 OpsItems(AWS CLI) - AWS Systems Manager

手动创建 OpsItems(AWS CLI)

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

使用 AWS CLI 创建 OpsItem
  1. 安装并配置 AWS Command Line Interface (AWS CLI)(如果尚未执行该操作)。

    有关信息,请参阅安装或更新 AWS CLI 的最新版本

  2. 打开 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 中将引号和字符串结合使用

    系统将返回类似于以下内容的信息。

    {
        "OpsItemId": "oi-1a2b3c4d5e6f"
    }
  3. 运行以下命令以查看有关您创建的 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"
                }
            }
        }
    }
  4. 运行以下命令以更新 OpsItem。此命令将状态从 Open(默认值)更改为 InProgress

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

    该命令没有输出。

  5. 再次运行以下命令以验证状态是否已更改为 InProgress

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

创建 OpsItem 的示例

以下代码示例向您演示如何使用 Linux 管理门户、macOS 或 Windows 创建 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 键创建将 AWS-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\"}}