AWS Systems Manager
用户指南
AWS 文档中描述的 AWS 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅中国的 AWS 服务入门

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

本教程演示了如何使用 AWS CLI 查看您已完成的维护时段任务执行的详细信息。

如果您是直接从教程:创建和配置维护时段 (AWS CLI) 继续,请确保您有允许的足够时间让维护时段至少运行一次来查看其执行结果。

As you follow the steps in this tutorial, replace the values in italicized red text with your own options and IDs. For example, replace the maintenance window ID mw-0c50858d01EXAMPLE and the instance ID i-02573cafcfEXAMPLE with IDs of resources you create.

查看有关任务和任务执行的信息 (AWS CLI)

  1. 运行以下命令,查看特定维护时段的任务执行列表:

    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. 运行以下命令,获取有关维护时段任务执行的信息:

    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. 运行以下命令,列出维护时段执行过程中运行的任务列表:

    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. 运行以下命令,获取有关任务执行的详情:

    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/aws-service-role/ssm.amazonaws.com/AWSServiceRoleForAmazonSSM",
        "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. 运行以下命令,获取执行某个任务时执行的具体任务调用。

    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
            }
        ]
    }