Tutorial: aggiornamento di una finestra di manutenzione (AWS CLI) - AWS Systems Manager

Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.

Tutorial: aggiornamento di una finestra di manutenzione (AWS CLI)

Questo tutorial dimostra come usare il AWS Command Line Interface (AWS CLI) per aggiornare una finestra di manutenzione. Mostra anche come aggiornare diversi tipi di attività, incluse quelle per AWS Systems Manager Run Command and Automation e AWS Step Functions. AWS Lambda

Gli esempi di questa sezione utilizzano le seguenti operazioni Systems Manager per l'aggiornamento di una finestra di manutenzione:

Per informazioni sull'utilizzo della console di Systems Manager per aggiornare una finestra di manutenzione, consulta Aggiornamento o eliminazione delle risorse della finestra di manutenzione (console).

Seguendo le fasi di questa esercitazione, sostituire valori in testo rosso in corsivo con i propri ID e opzioni. Ad esempio, sostituire l'ID della finestra di manutenzione mw-0c50858d01EXAMPLE e l'ID dell'istanza i-02573cafcfEXAMPLE con ID di risorse create.

Per aggiornare una finestra di manutenzione (AWS CLI)
  1. Apri AWS CLI ed esegui il comando seguente per aggiornare una destinazione in modo da includere un nome e una descrizione.

    Linux & macOS
    aws ssm update-maintenance-window-target \ --window-id "mw-0c50858d01EXAMPLE" \ --window-target-id "e32eecb2-646c-4f4b-8ed1-205fbEXAMPLE" \ --name "My-Maintenance-Window-Target" \ --description "Description for my maintenance window target"
    Windows
    aws ssm update-maintenance-window-target ^ --window-id "mw-0c50858d01EXAMPLE" ^ --window-target-id "e32eecb2-646c-4f4b-8ed1-205fbEXAMPLE" ^ --name "My-Maintenance-Window-Target" ^ --description "Description for my maintenance window target"

    Il sistema restituisce informazioni simili alle seguenti.

    {
        "WindowId": "mw-0c50858d01EXAMPLE",
        "WindowTargetId": "e32eecb2-646c-4f4b-8ed1-205fbEXAMPLE",
        "Targets": [
            {
                "Key": "InstanceIds",
                "Values": [
                    "i-02573cafcfEXAMPLE"
                ]
            }
        ],
        "Name": "My-Maintenance-Window-Target",
        "Description": "Description for my maintenance window target"
    }
  2. Eseguire questo comando per utilizzare l'opzione replace per rimuovere il campo descrizione e aggiungere un'ulteriore destinazione. Il campo descrizione è rimosso, perché l'aggiornamento non include il campo (valore nullo). Assicurarsi di specificare un nodo aggiuntivo configurato per l'utilizzo con Systems Manager.

    Linux & macOS
    aws ssm update-maintenance-window-target \ --window-id "mw-0c50858d01EXAMPLE" \ --window-target-id "d208dedf-3f6b-41ff-ace8-8e751EXAMPLE" \ --targets "Key=InstanceIds,Values=i-02573cafcfEXAMPLE,i-0471e04240EXAMPLE" \ --name "My-Maintenance-Window-Target" \ --replace
    Windows
    aws ssm update-maintenance-window-target ^ --window-id "mw-0c50858d01EXAMPLE" ^ --window-target-id "d208dedf-3f6b-41ff-ace8-8e751EXAMPLE" ^ --targets "Key=InstanceIds,Values=i-02573cafcfEXAMPLE,i-0471e04240EXAMPLE" ^ --name "My-Maintenance-Window-Target" ^ --replace

    Il sistema restituisce informazioni simili alle seguenti.

    {
        "WindowId": "mw-0c50858d01EXAMPLE",
        "WindowTargetId": "e32eecb2-646c-4f4b-8ed1-205fbEXAMPLE",
        "Targets": [
            {
                "Key": "InstanceIds",
                "Values": [
                    "i-02573cafcfEXAMPLE",
                    "i-0471e04240EXAMPLE"
                ]
            }
        ],
        "Name": "My-Maintenance-Window-Target"
    }
  3. L'opzione start-date permette di ritardare l'attivazione di una finestra di manutenzione fino a una data futura indicata. L'opzione end-date permette di impostare una data e un'ora nel futuro dopo la quale la finestra di manutenzione non sarà più eseguita. Specificare le opzioni in formato ISO-8601 Extended.

    Eseguire il comando seguente per specificare un intervallo di data e ora per esecuzioni regolarmente pianificate della finestra di manutenzione.

    Linux & macOS
    aws ssm update-maintenance-window \ --window-id "mw-0c50858d01EXAMPLE" \ --start-date "2020-10-01T10:10:10Z" \ --end-date "2020-11-01T10:10:10Z"
    Windows
    aws ssm update-maintenance-window ^ --window-id "mw-0c50858d01EXAMPLE" ^ --start-date "2020-10-01T10:10:10Z" ^ --end-date "2020-11-01T10:10:10Z"
  4. Esegui il seguente comando per aggiornare un task Run Command.

    Suggerimento

    Se il target è un'istanza Amazon Elastic Compute Cloud (Amazon EC2) per Windows Server, modifica da df a ipconfig e da AWS-RunShellScript a AWS-RunPowerShellScript nel comando seguente.

    Linux & macOS
    aws ssm update-maintenance-window-task \ --window-id "mw-0c50858d01EXAMPLE" \ --window-task-id "4f7ca192-7e9a-40fe-9192-5cb15EXAMPLE" \ --targets "Key=WindowTargetIds,Values=e32eecb2-646c-4f4b-8ed1-205fbEXAMPLE" \ --task-arn "AWS-RunShellScript" \ --service-role-arn "arn:aws:iam::account-id:role/MaintenanceWindowsRole" \ --task-invocation-parameters "RunCommand={Comment=Revising my Run Command task,Parameters={commands=df}}" \ --priority 1 --max-concurrency 10 --max-errors 4 \ --name "My-Task-Name" --description "A description for my Run Command task"
    Windows
    aws ssm update-maintenance-window-task ^ --window-id "mw-0c50858d01EXAMPLE" ^ --window-task-id "4f7ca192-7e9a-40fe-9192-5cb15EXAMPLE" ^ --targets "Key=WindowTargetIds,Values=e32eecb2-646c-4f4b-8ed1-205fbEXAMPLE" ^ --task-arn "AWS-RunShellScript" ^ --service-role-arn "arn:aws:iam::account-id:role/MaintenanceWindowsRole" ^ --task-invocation-parameters "RunCommand={Comment=Revising my Run Command task,Parameters={commands=df}}" ^ --priority 1 --max-concurrency 10 --max-errors 4 ^ --name "My-Task-Name" --description "A description for my Run Command task"

    Il sistema restituisce informazioni simili alle seguenti.

    {
        "WindowId": "mw-0c50858d01EXAMPLE",
        "WindowTaskId": "4f7ca192-7e9a-40fe-9192-5cb15EXAMPLE",
        "Targets": [
            {
                "Key": "WindowTargetIds",
                "Values": [
                    "e32eecb2-646c-4f4b-8ed1-205fbEXAMPLE"
                ]
            }
        ],
        "TaskArn": "AWS-RunShellScript",
        "ServiceRoleArn": "arn:aws:iam::111122223333:role/MaintenanceWindowsRole",
        "TaskParameters": {},
        "TaskInvocationParameters": {
            "RunCommand": {
                "Comment": "Revising my Run Command task",
                "Parameters": {
                    "commands": [
                        "df"
                    ]
                }
            }
        },
        "Priority": 1,
        "MaxConcurrency": "10",
        "MaxErrors": "4",
        "Name": "My-Task-Name",
        "Description": "A description for my Run Command task"
    }
  5. Adatta ed esegui il seguente comando per aggiornare un task Lambda.

    Linux & macOS
    aws ssm update-maintenance-window-task \ --window-id mw-0c50858d01EXAMPLE \ --window-task-id 4f7ca192-7e9a-40fe-9192-5cb15EXAMPLE \ --targets "Key=WindowTargetIds,Values=e32eecb2-646c-4f4b-8ed1-205fbEXAMPLE" \ --task-arn "arn:aws:lambda:region:111122223333:function:SSMTestLambda" \ --service-role-arn "arn:aws:iam:account-id:role/MaintenanceWindowsRole" \ --task-invocation-parameters '{"Lambda":{"Payload":"{\"InstanceId\":\"{{RESOURCE_ID}}\",\"targetType\":\"{{TARGET_TYPE}}\"}"}}' \ --priority 1 --max-concurrency 10 --max-errors 5 \ --name "New-Lambda-Task-Name" \ --description "A description for my Lambda task"
    Windows
    aws ssm update-maintenance-window-task ^ --window-id mw-0c50858d01EXAMPLE ^ --window-task-id 4f7ca192-7e9a-40fe-9192-5cb15EXAMPLE ^ --targets "Key=WindowTargetIds,Values=e32eecb2-646c-4f4b-8ed1-205fbEXAMPLE" ^ --task-arn --task-arn "arn:aws:lambda:region:111122223333:function:SSMTestLambda" ^ --service-role-arn "arn:aws:iam:account-id:role/MaintenanceWindowsRole" ^ --task-invocation-parameters '{"Lambda":{"Payload":"{\"InstanceId\":\"{{RESOURCE_ID}}\",\"targetType\":\"{{TARGET_TYPE}}\"}"}}' ^ --priority 1 --max-concurrency 10 --max-errors 5 ^ --name "New-Lambda-Task-Name" ^ --description "A description for my Lambda task"

    Il sistema restituisce informazioni simili alle seguenti.

    {
        "WindowId": "mw-0c50858d01EXAMPLE",
        "WindowTaskId": "4f7ca192-7e9a-40fe-9192-5cb15EXAMPLE",
        "Targets": [
            {
                "Key": "WindowTargetIds",
                "Values": "e32eecb2-646c-4f4b-8ed1-205fbEXAMPLE"
            }
        ],
        "TaskArn": "arn:aws:lambda:us-east-2:111122223333:function:SSMTestLambda",
        "ServiceRoleArn": "arn:aws:iam::111122223333:role/MaintenanceWindowsRole",
        "TaskParameters": {},
        "TaskInvocationParameters": {
            "Lambda": {
                "Payload": "e30="
            }
        },
        "Priority": 1,
        "MaxConcurrency": "10",
        "MaxErrors": "5",
        "Name": "New-Lambda-Task-Name",
        "Description": "A description for my Lambda task"
    }
  6. Se stai aggiornando un'attività Step Functions, adatta ed esegui il comando seguente per aggiornarla task-invocation-parameters.

    Linux & macOS
    aws ssm update-maintenance-window-task \ --window-id "mw-0c50858d01EXAMPLE" \ --window-task-id "4f7ca192-7e9a-40fe-9192-5cb15EXAMPLE" \ --targets "Key=WindowTargetIds,Values=e32eecb2-646c-4f4b-8ed1-205fbEXAMPLE" \ --task-arn "arn:aws:states:region:execution:SSMStepFunctionTest" \ --service-role-arn "arn:aws:iam:account-id:role/MaintenanceWindowsRole" \ --task-invocation-parameters '{"StepFunctions":{"Input":"{\"InstanceId\":\"{{RESOURCE_ID}}\"}"}}' \ --priority 0 --max-concurrency 10 --max-errors 5 \ --name "My-Step-Functions-Task" \ --description "A description for my Step Functions task"
    Windows
    aws ssm update-maintenance-window-task ^ --window-id "mw-0c50858d01EXAMPLE" ^ --window-task-id "4f7ca192-7e9a-40fe-9192-5cb15EXAMPLE" ^ --targets "Key=WindowTargetIds,Values=e32eecb2-646c-4f4b-8ed1-205fbEXAMPLE" ^ --task-arn "arn:aws:states:region:execution:SSMStepFunctionTest" ^ --service-role-arn "arn:aws:iam:account-id:role/MaintenanceWindowsRole" ^ --task-invocation-parameters '{"StepFunctions":{"Input":"{\"InstanceId\":\"{{RESOURCE_ID}}\"}"}}' ^ --priority 0 --max-concurrency 10 --max-errors 5 ^ --name "My-Step-Functions-Task" ^ --description "A description for my Step Functions task"

    Il sistema restituisce informazioni simili alle seguenti.

    {
        "WindowId": "mw-0c50858d01EXAMPLE",
        "WindowTaskId": "4f7ca192-7e9a-40fe-9192-5cb15EXAMPLE",
        "Targets": [
            {
                "Key": "WindowTargetIds",
                "Values": [
                    "e32eecb2-646c-4f4b-8ed1-205fbEXAMPLE"
                ]
            }
        ],
        "TaskArn": "arn:aws:states:us-east-2:111122223333:execution:SSMStepFunctionTest",
        "ServiceRoleArn": "arn:aws:iam::111122223333:role/MaintenanceWindowsRole",
        "TaskParameters": {},
        "TaskInvocationParameters": {
            "StepFunctions": {
                "Input": "{\"instanceId\":\"{{RESOURCE_ID}}\"}"
            }
        },
        "Priority": 0,
        "MaxConcurrency": "10",
        "MaxErrors": "5",
        "Name": "My-Step-Functions-Task",
        "Description": "A description for my Step Functions task"
    }
  7. Eseguire il comando seguente per annullare la registrazione di una destinazione da una finestra di manutenzione. Questo esempio utilizza il parametro safe per determinare se la destinazione è referenziata da una qualsiasi e quindi se l'annullamento della registrazione è sicuro.

    Linux & macOS
    aws ssm deregister-target-from-maintenance-window \ --window-id "mw-0c50858d01EXAMPLE" \ --window-target-id "e32eecb2-646c-4f4b-8ed1-205fbEXAMPLE" \ --safe
    Windows
    aws ssm deregister-target-from-maintenance-window ^ --window-id "mw-0c50858d01EXAMPLE" ^ --window-target-id "e32eecb2-646c-4f4b-8ed1-205fbEXAMPLE" ^ --safe

    Il sistema restituisce informazioni simili alle seguenti.

    An error occurred (TargetInUseException) when calling the DeregisterTargetFromMaintenanceWindow operation: 
    This Target cannot be deregistered because it is still referenced in Task: 4f7ca192-7e9a-40fe-9192-5cb15EXAMPLE
  8. Eseguire il comando seguente per annullare la registrazione di una destinazione da una finestra di manutenzione anche se la destinazione è referenziata da un'attività. È possibile forzare l'operazione di annullamento della registrazione utilizzando il parametro no-safe.

    Linux & macOS
    aws ssm deregister-target-from-maintenance-window \ --window-id "mw-0c50858d01EXAMPLE" \ --window-target-id "e32eecb2-646c-4f4b-8ed1-205fbEXAMPLE" \ --no-safe
    Windows
    aws ssm deregister-target-from-maintenance-window ^ --window-id "mw-0c50858d01EXAMPLE" ^ --window-target-id "e32eecb2-646c-4f4b-8ed1-205fbEXAMPLE" ^ --no-safe

    Il sistema restituisce informazioni simili alle seguenti.

    {
        "WindowId": "mw-0c50858d01EXAMPLE",
        "WindowTargetId": "e32eecb2-646c-4f4b-8ed1-205fbEXAMPLE"
    }
    
  9. Esegui il seguente comando per aggiornare un task Run Command. Questo esempio utilizza un parametro Parameter Store Systems Manager denominato UpdateLevel, formattato nel seguente modo: '{{ssm:UpdateLevel}}'

    Linux & macOS
    aws ssm update-maintenance-window-task \ --window-id "mw-0c50858d01EXAMPLE" \ --window-task-id "4f7ca192-7e9a-40fe-9192-5cb15EXAMPLE" \ --targets "Key=InstanceIds,Values=i-02573cafcfEXAMPLE" \ --task-invocation-parameters "RunCommand={Comment=A comment for my task update,Parameters={UpdateLevel='{{ssm:UpdateLevel}}'}}"
    Windows
    aws ssm update-maintenance-window-task ^ --window-id "mw-0c50858d01EXAMPLE" ^ --window-task-id "4f7ca192-7e9a-40fe-9192-5cb15EXAMPLE" ^ --targets "Key=InstanceIds,Values=i-02573cafcfEXAMPLE" ^ --task-invocation-parameters "RunCommand={Comment=A comment for my task update,Parameters={UpdateLevel='{{ssm:UpdateLevel}}'}}"

    Il sistema restituisce informazioni simili alle seguenti.

    {
        "WindowId": "mw-0c50858d01EXAMPLE",
        "WindowTaskId": "4f7ca192-7e9a-40fe-9192-5cb15EXAMPLE",
        "Targets": [
            {
                "Key": "InstanceIds",
                "Values": [
                    "i-02573cafcfEXAMPLE"
                ]
            }
        ],
        "TaskArn": "AWS-RunShellScript",
        "ServiceRoleArn": "arn:aws:iam::111122223333:role/MyMaintenanceWindowServiceRole",
        "TaskParameters": {},
        "TaskInvocationParameters": {
            "RunCommand": {
                "Comment": "A comment for my task update",
                "Parameters": {
                    "UpdateLevel": [
                        "{{ssm:UpdateLevel}}"
                    ]
                }
            }
        },
        "Priority": 10,
        "MaxConcurrency": "1",
        "MaxErrors": "1"
    }
  10. Eseguire questo comando per aggiornare un'attività di automazione per specificare i parametri WINDOW_ID e WINDOW_TASK_ID per il parametro task-invocation-parameters:

    Linux & macOS
    aws ssm update-maintenance-window-task \ --window-id "mw-0c50858d01EXAMPLE" \ --window-task-id "4f7ca192-7e9a-40fe-9192-5cb15EXAMPLE" \ --targets "Key=WindowTargetIds,Values=e32eecb2-646c-4f4b-8ed1-205fbEXAMPLE \ --task-arn "AutoTestDoc" \ --service-role-arn "arn:aws:iam:account-id:role/MyMaintenanceWindowServiceRole \ --task-invocation-parameters "Automation={Parameters={InstanceId='{{RESOURCE_ID}}',initiator='{{WINDOW_ID}}.Task-{{WINDOW_TASK_ID}}'}}" \ --priority 3 --max-concurrency 10 --max-errors 5
    Windows
    aws ssm update-maintenance-window-task ^ --window-id "mw-0c50858d01EXAMPLE" ^ --window-task-id "4f7ca192-7e9a-40fe-9192-5cb15EXAMPLE" ^ --targets "Key=WindowTargetIds,Values=e32eecb2-646c-4f4b-8ed1-205fbEXAMPLE ^ --task-arn "AutoTestDoc" ^ --service-role-arn "arn:aws:iam:account-id:role/MyMaintenanceWindowServiceRole ^ --task-invocation-parameters "Automation={Parameters={InstanceId='{{RESOURCE_ID}}',initiator='{{WINDOW_ID}}.Task-{{WINDOW_TASK_ID}}'}}" ^ --priority 3 --max-concurrency 10 --max-errors 5

    Il sistema restituisce informazioni simili alle seguenti.

    {
        "WindowId": "mw-0c50858d01EXAMPLE",
        "WindowTaskId": "4f7ca192-7e9a-40fe-9192-5cb15EXAMPLE",
        "Targets": [
            {
                "Key": "WindowTargetIds",
                "Values": [
                    "e32eecb2-646c-4f4b-8ed1-205fbEXAMPLE"
                ]
            }
        ],
        "TaskArn": "AutoTestDoc",
        "ServiceRoleArn": "arn:aws:iam::111122223333:role/MyMaintenanceWindowServiceRole",
        "TaskParameters": {},
        "TaskInvocationParameters": {
            "Automation": {
                "Parameters": {
                    "multi": [
                        "{{WINDOW_TASK_ID}}"
                    ],
                    "single": [
                        "{{WINDOW_ID}}"
                    ]
                }
            }
        },
        "Priority": 0,
        "MaxConcurrency": "10",
        "MaxErrors": "5",
        "Name": "My-Automation-Task",
        "Description": "A description for my Automation task"
    }