教學課程:檢視任務和任務執行的相關資訊 (AWS CLI) - AWS Systems Manager

教學課程:檢視任務和任務執行的相關資訊 (AWS CLI)

本教學課程示範如何使用 AWS Command Line Interface (AWS CLI) 來檢視已完成維護時段任務執行的相關詳細資訊。

如果您直接從 教學課程:建立和設定維護時段 (AWS CLI) 繼續執行,請確保維護時段有足夠的時間可執行至少一次,以查看其執行的結果。

當您按照此教學課程中的步驟,使用自己的選項和 ID 來取代斜體紅色文字。例如,使用您所建立之資源 ID 取代維護時段 ID mw-0c50858d01EXAMPLE 和執行個體 ID i-02573cafcfEXAMPLE

檢視與任務和任務執行相關的資訊 (AWS 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
            }
        ]
    }