手动运行自动化 - Amazon Systems Manager
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

手动运行自动化

以下过程介绍了如何通过手动执行模式使用 Amazon Systems Manager 控制台和 Amazon Command Line Interface (Amazon CLI) 运行自动化。通过使用手动执行模式,自动化在两个步骤之间从等待状态开始,在等待状态暂停。这允许您控制自动化何时继续,如果您需要先查看某个步骤的结果,然后再继续,这会很有用。

自动化在当前用户的上下文中运行。因此,只要您有权使用运行手册和此运行手册调用的任何操作,就无需配置其他 IAM 权限。如果您在 IAM 中拥有管理员权限,则已有权运行此自动化。

按步骤运行自动化(控制台)

以下过程介绍了如何使用 Systems Manager 控制台按步骤手动运行自动化。

要按步骤运行自动化,请执行以下操作
  1. 访问 https://console.aws.amazon.com/systems-manager/,打开 Amazon Systems Manager 控制台。

  2. 在导航窗格中,选择自动化,然后选择执行自动化

  3. 自动化文档列表中,请选择运行手册。在文档类别窗格中选择一个或多个选项,以便根据 SSM 文档的用途对其进行筛选。要查看您拥有的运行手册,请选择我拥有的选项卡。要查看与您的账户共享的运行手册,请选择与我共享选项卡。要查看所有运行手册,请选择所有文档选项卡。

    注意

    您可以通过选择运行手册名称来查看有关该手册的信息。

  4. 文档详细信息部分中,验证文档版本已设置为要运行的版本。系统包括以下版本选项:

    • 运行时的默认版本 – 如果定期更新自动化运行手册并分配新的默认版本,请选择此选项。

    • 运行时的最新版本 – 如果定期更新自动化运行手册并且想要运行最新更新的版本,请选择此选项。

    • 1(默认) – 选择此选项可执行文档的第一个版本,即默认版本。

  5. 选择下一步

  6. 执行模式部分中,选择手动执行

  7. 输入参数部分中,指定所需的输入。或者,您也可以从 AutomationAssumeRole 列表选择一个 IAM 服务角色。

  8. 选择执行

  9. 当您准备好开始自动化的第一步时,选择执行此步骤。自动化将执行步骤 1,并在运行您在此过程的步骤 3 中选择的运行手册中指定的任何后续步骤之前暂停。如果运行手册具有多个步骤,则必须为每个步骤选择执行此步骤以让自动化继续。每次选择执行此步骤,操作就会运行。

    注意

    控制台将显示自动化的状态。如果自动化无法运行某个步骤,请参阅 Systems Manager 自动化故障排除

  10. 在完成运行手册中指定的所有步骤后,选择完成并查看结果以完成自动化并查看结果。

按步骤运行自动化(命令行)

以下过程介绍了如何使用 Amazon CLI(在 Linux、macOS 或 Windows 中)或 Amazon Tools for PowerShell 按步骤手动运行自动化。

要按步骤运行自动化,请执行以下操作:
  1. 安装并配置 Amazon CLI 或 Amazon Tools for PowerShell(如果尚未执行该操作)。

    有关信息,请参阅安装或更新 Amazon CLI 的最新版本以及安装 Amazon Tools for PowerShell

  2. 运行以下命令以启动一个手动自动化。将每个示例资源占位符替换为您自己的信息。

    Linux & macOS
    aws ssm start-automation-execution \ --document-name runbook name \ --mode Interactive \ --parameters runbook parameters
    Windows
    aws ssm start-automation-execution ^ --document-name runbook name ^ --mode Interactive ^ --parameters runbook parameters
    PowerShell
    Start-SSMAutomationExecution ` -DocumentName runbook name ` -Mode Interactive ` -Parameter runbook parameters

    以下是使用 AWS-RestartEC2Instance 运行手册重新启动指定 EC2 实例的示例。

    Linux & macOS
    aws ssm start-automation-execution \ --document-name "AWS-RestartEC2Instance" \ --mode Interactive \ --parameters "InstanceId=i-02573cafcfEXAMPLE"
    Windows
    aws ssm start-automation-execution ^ --document-name "AWS-RestartEC2Instance" ^ --mode Interactive ^ --parameters "InstanceId=i-02573cafcfEXAMPLE"
    PowerShell
    Start-SSMAutomationExecution ` -DocumentName AWS-RestartEC2Instance ` -Mode Interactive -Parameter @{"InstanceId"="i-02573cafcfEXAMPLE"}

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

    Linux & macOS
    {
        "AutomationExecutionId": "ba9cd881-1b36-4d31-a698-0123456789ab"
    }
    Windows
    {
        "AutomationExecutionId": "ba9cd881-1b36-4d31-a698-0123456789ab"
    }
    PowerShell
    ba9cd881-1b36-4d31-a698-0123456789ab
  3. 在准备好开始执行自动化的第一步时,运行以下命令。将每个示例资源占位符替换为您自己的信息。自动化将执行步骤 1,并在运行您在该过程的步骤 1 中选择的运行手册中指定的任何后续步骤之前暂停。如果运行手册具有多个步骤,则必须为每个步骤运行以下命令以使自动化继续执行。

    Linux & macOS
    aws ssm send-automation-signal \ --automation-execution-id ba9cd881-1b36-4d31-a698-0123456789ab \ --signal-type StartStep \ --payload StepName="stopInstances"
    Windows
    aws ssm send-automation-signal ^ --automation-execution-id ba9cd881-1b36-4d31-a698-0123456789ab ^ --signal-type StartStep ^ --payload StepName="stopInstances"
    PowerShell
    Send-SSMAutomationSignal ` -AutomationExecutionId ba9cd881-1b36-4d31-a698-0123456789ab ` -SignalType StartStep -Payload @{"StepName"="stopInstances"}

    如果此命令成功,则无任何输出。

  4. 运行以下命令以检索自动化中的每个步骤执行的状态。

    Linux & macOS
    aws ssm describe-automation-step-executions \ --automation-execution-id ba9cd881-1b36-4d31-a698-0123456789ab
    Windows
    aws ssm describe-automation-step-executions ^ --automation-execution-id ba9cd881-1b36-4d31-a698-0123456789ab
    PowerShell
    Get-SSMAutomationStepExecution ` -AutomationExecutionId ba9cd881-1b36-4d31-a698-0123456789ab

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

    Linux & macOS
    {
        "StepExecutions": [
            {
                "StepName": "stopInstances",
                "Action": "aws:changeInstanceState",
                "ExecutionStartTime": 1557167178.42,
                "ExecutionEndTime": 1557167220.617,
                "StepStatus": "Success",
                "Inputs": {
                    "DesiredState": "\"stopped\"",
                    "InstanceIds": "[\"i-02573cafcfEXAMPLE\"]"
                },
                "Outputs": {
                    "InstanceStates": [
                        "stopped"
                    ]
                },
                "StepExecutionId": "654243ba-71e3-4771-b04f-0123456789ab",
                "OverriddenParameters": {},
                "ValidNextSteps": [
                    "startInstances"
                ]
            },
            {
                "StepName": "startInstances",
                "Action": "aws:changeInstanceState",
                "ExecutionStartTime": 1557167273.754,
                "ExecutionEndTime": 1557167480.73,
                "StepStatus": "Success",
                "Inputs": {
                    "DesiredState": "\"running\"",
                    "InstanceIds": "[\"i-02573cafcfEXAMPLE\"]"
                },
                "Outputs": {
                    "InstanceStates": [
                        "running"
                    ]
                },
                "StepExecutionId": "8a4a1e0d-dc3e-4039-a599-0123456789ab",
                "OverriddenParameters": {}
            }
        ]
    }
    Windows
    {
        "StepExecutions": [
            {
                "StepName": "stopInstances",
                "Action": "aws:changeInstanceState",
                "ExecutionStartTime": 1557167178.42,
                "ExecutionEndTime": 1557167220.617,
                "StepStatus": "Success",
                "Inputs": {
                    "DesiredState": "\"stopped\"",
                    "InstanceIds": "[\"i-02573cafcfEXAMPLE\"]"
                },
                "Outputs": {
                    "InstanceStates": [
                        "stopped"
                    ]
                },
                "StepExecutionId": "654243ba-71e3-4771-b04f-0123456789ab",
                "OverriddenParameters": {},
                "ValidNextSteps": [
                    "startInstances"
                ]
            },
            {
                "StepName": "startInstances",
                "Action": "aws:changeInstanceState",
                "ExecutionStartTime": 1557167273.754,
                "ExecutionEndTime": 1557167480.73,
                "StepStatus": "Success",
                "Inputs": {
                    "DesiredState": "\"running\"",
                    "InstanceIds": "[\"i-02573cafcfEXAMPLE\"]"
                },
                "Outputs": {
                    "InstanceStates": [
                        "running"
                    ]
                },
                "StepExecutionId": "8a4a1e0d-dc3e-4039-a599-0123456789ab",
                "OverriddenParameters": {}
            }
        ]
    }
    PowerShell
    Action: aws:changeInstanceState
    ExecutionEndTime     : 5/6/2019 19:45:46
    ExecutionStartTime   : 5/6/2019 19:45:03
    FailureDetails       : 
    FailureMessage       : 
    Inputs               : {[DesiredState, "stopped"], [InstanceIds, ["i-02573cafcfEXAMPLE"]]}
    IsCritical           : False
    IsEnd                : False
    MaxAttempts          : 0
    NextStep             : 
    OnFailure            : 
    Outputs              : {[InstanceStates, Amazon.Runtime.Internal.Util.AlwaysSendList`1[System.String]]}
    OverriddenParameters : {}
    Response             : 
    ResponseCode         : 
    StepExecutionId      : 8fcc9641-24b7-40b3-a9be-0123456789ab
    StepName             : stopInstances
    StepStatus           : Success
    TimeoutSeconds       : 0
    ValidNextSteps       : {startInstances}
  5. 在完成所选运行手册中指定的所有步骤后,运行以下命令以完成自动化。将每个示例资源占位符替换为您自己的信息。

    Linux & macOS
    aws ssm stop-automation-execution \ --automation-execution-id ba9cd881-1b36-4d31-a698-0123456789ab \ --type Complete
    Windows
    aws ssm stop-automation-execution ^ --automation-execution-id ba9cd881-1b36-4d31-a698-0123456789ab ^ --type Complete
    PowerShell
    Stop-SSMAutomationExecution ` -AutomationExecutionId ba9cd881-1b36-4d31-a698-0123456789ab ` -Type Complete

    如果此命令成功,则无任何输出。