教程:查看有关任务和任务执行的信息 (Amazon CLI) - Amazon Systems Manager
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

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

教程:查看有关任务和任务执行的信息 (Amazon CLI)

本教程演示了如何使用 Amazon Command Line Interface (Amazon CLI) 查看有关您已完成的维护时段任务的详细信息。

如果您直接从 教程:创建和配置维护时段 (Amazon CLI) 继续,请确保您已为维护时段留出足够时间至少运行一次,以查看其执行结果。

在按照本教程中的步骤操作时,请将以斜体红色文本显示的值替换为您自己的选项和 ID。例如,请将维护时段 ID mw-0c50858d01EXAMPLE 和实例 ID i-02573cafcfEXAMPLE 替换为您创建的资源的 ID。

查看有关任务和任务执行的信息 (Amazon CLI)
  1. 运行以下命令,查看特定维护时段的任务执行列表。

    Linux & macOS
    aws ssm describe-maintenance-window-executions \ --window-id "mw-0c50858d01EXAMPLE"
    Windows
    aws ssm describe-maintenance-window-executions ^ --window-id "mw-0c50858d01EXAMPLE"

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

    {
        "WindowExecutions": [
            {
                "WindowId": "mw-0c50858d01EXAMPLE",
                "WindowExecutionId": "14bea65d-5ccc-462d-a2f3-e99c8EXAMPLE",
                "Status": "SUCCESS",
                "StartTime": 1557593793.483,
                "EndTime": 1557593798.978
            },
            {
                "WindowId": "mw-0c50858d01EXAMPLE",
                "WindowExecutionId": "791b72e0-f0da-4021-8b35-f95dfEXAMPLE",
                "Status": "SUCCESS",
                "StartTime": 1557593493.096,
                "EndTime": 1557593498.611
            },
            {
                "WindowId": "mw-0c50858d01EXAMPLE",
                "WindowExecutionId": "ecec60fa-6bb0-4d26-98c7-140308EXAMPLE",
                "Status": "SUCCESS",
                "StatusDetails": "No tasks to execute.",
                "StartTime": 1557593193.309,
                "EndTime": 1557593193.334
            }
        ]
    }
  2. 运行以下命令,获取有关维护时段任务执行的信息。

    Linux & macOS
    aws ssm get-maintenance-window-execution \ --window-execution-id "14bea65d-5ccc-462d-a2f3-e99c8EXAMPLE"
    Windows
    aws ssm get-maintenance-window-execution ^ --window-execution-id "14bea65d-5ccc-462d-a2f3-e99c8EXAMPLE"

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

    {
        "WindowExecutionId": "14bea65d-5ccc-462d-a2f3-e99c8EXAMPLE",
        "TaskIds": [
            "c9b05aba-197f-4d8d-be34-e73fbEXAMPLE"
        ],
        "Status": "SUCCESS",
        "StartTime": 1557593493.096,
        "EndTime": 1557593498.611
    }
  3. 运行以下命令,列出作为维护时段执行的组成部分运行的任务。

    Linux & macOS
    aws ssm describe-maintenance-window-execution-tasks \ --window-execution-id "14bea65d-5ccc-462d-a2f3-e99c8EXAMPLE"
    Windows
    aws ssm describe-maintenance-window-execution-tasks ^ --window-execution-id "14bea65d-5ccc-462d-a2f3-e99c8EXAMPLE"

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

    {
        "WindowExecutionTaskIdentities": [
            {
                "WindowExecutionId": "14bea65d-5ccc-462d-a2f3-e99c8EXAMPLE",
                "TaskExecutionId": "c9b05aba-197f-4d8d-be34-e73fbEXAMPLE",
                "Status": "SUCCESS",
                "StartTime": 1557593493.162,
                "EndTime": 1557593498.57,
                "TaskArn": "AWS-RunShellScript",
                "TaskType": "RUN_COMMAND"
            }
        ]
    }
  4. 运行以下命令,获取有关任务执行的详情。

    Linux & macOS
    aws ssm get-maintenance-window-execution-task \ --window-execution-id "14bea65d-5ccc-462d-a2f3-e99c8EXAMPLE" \ --task-id "c9b05aba-197f-4d8d-be34-e73fbEXAMPLE"
    Windows
    aws ssm get-maintenance-window-execution-task ^ --window-execution-id "14bea65d-5ccc-462d-a2f3-e99c8EXAMPLE" ^ --task-id "c9b05aba-197f-4d8d-be34-e73fbEXAMPLE"

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

    {
        "WindowExecutionId": "14bea65d-5ccc-462d-a2f3-e99c8EXAMPLE",
        "TaskExecutionId": "c9b05aba-197f-4d8d-be34-e73fbEXAMPLE",
        "TaskArn": "AWS-RunShellScript",
        "ServiceRole": "arn:aws:iam::111122223333:role/MyMaintenanceWindowServiceRole",
        "Type": "RUN_COMMAND",
        "TaskParameters": [
            {
                "aws:InstanceId": {
                    "Values": [
                        "i-02573cafcfEXAMPLE"
                    ]
                },
                "commands": {
                    "Values": [
                        "df"
                    ]
                }
            }
        ],
        "Priority": 10,
        "MaxConcurrency": "1",
        "MaxErrors": "1",
        "Status": "SUCCESS",
        "StartTime": 1557593493.162,
        "EndTime": 1557593498.57
    }
  5. 运行以下命令,获取执行某个任务时执行的具体任务调用。

    Linux & macOS
    aws ssm describe-maintenance-window-execution-task-invocations \ --window-execution-id "14bea65d-5ccc-462d-a2f3-e99c8EXAMPLE" \ --task-id "c9b05aba-197f-4d8d-be34-e73fbEXAMPLE"
    Windows
    aws ssm describe-maintenance-window-execution-task-invocations ^ --window-execution-id "14bea65d-5ccc-462d-a2f3-e99c8EXAMPLE" ^ --task-id "c9b05aba-197f-4d8d-be34-e73fbEXAMPLE"

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

    {
        "WindowExecutionTaskInvocationIdentities": [
            {
                "WindowExecutionId": "14bea65d-5ccc-462d-a2f3-e99c8EXAMPLE",
                "TaskExecutionId": "c9b05aba-197f-4d8d-be34-e73fbEXAMPLE",
                "InvocationId": "c336d2ab-09de-44ba-8f6a-6136cEXAMPLE",
                "ExecutionId": "76a5a04f-caf6-490c-b448-92c02EXAMPLE",
                "TaskType": "RUN_COMMAND",
                "Parameters": "{\"documentName\":\"AWS-RunShellScript\",\"instanceIds\":[\"i-02573cafcfEXAMPLE\"],\"maxConcurrency\":\"1\",\"maxErrors\":\"1\",\"parameters\":{\"commands\":[\"df\"]}}",
                "Status": "SUCCESS",
                "StatusDetails": "Success",
                "StartTime": 1557593493.222,
                "EndTime": 1557593498.466
            }
        ]
    }