InvalidPluginName 中的 AWS System Manager (SSM) get-command-invocation 结果

AWS System Manager (SSM) get-command-invocation results in InvalidPluginName

我已经能够成功地将 SSM 命令发送到 EC2 实例。

这是我正在使用的 Python Lambda 代码:

            # System Manager send_command
            response = ssm_client.send_command(
                        InstanceIds=[instanceID],
                        DocumentName=document,
                        Parameters={'action': ['Install'],'licenseKey': [licenseKeyValue],})
                        
            command_id = response['Command']['CommandId']
            print("Command ID: " + command_id)

文档是:arn:aws:ssm:us-east-2:539736333151:document/New-Relic_Infrastructure

[更新:问题出在具有多个插件(操作)的文档中,而该文档确实如此。必须使用 --plugin-name correctName 来获取状态。]

我知道 send_command 正在使用此文档。我也知道 commandID.

我已经在实例和 AWS CLI for Systems Manager -> 运行 命令界面中看到了结果。

现在,我正在尝试通过 get-command-invocation 检索命令状态。我的 AWS CLI 命令:

aws ssm get-command-invocation --command-id 28XXXa35-dXX1-4XX1-9XX0-9ecfXXXX29ae --instance-id i-0c038XXXXc4e9c66e

我收到了这样的回复:

An error occurred (InvalidPluginName) when calling the GetCommandInvocation operation:

我也试过:

aws ssm get-command-invocation --command-id 28XXXa35-dXX1-4XX1-9XX0-9ecfXXXX29ae --instance-id i-0c038XXXXc4e9c66e --plugin-name runShellScript

完全相同的响应。

关于为什么我收到无效插件错误的任何想法当它是可选的

来自:aws ssm get-command-invocation 帮助

SYNOPSIS

        get-command-invocation
      --command-id <value>
      --instance-id <value>
      [--plugin-name <value>]
      [--cli-input-json | --cli-input-yaml]
      [--generate-cli-skeleton <value>]
      [--cli-auto-prompt <value>]

OPTIONS

   --command-id (string)
      (Required) The parent command ID of the invocation plugin.

   --instance-id (string)
      (Required) The ID of the managed instance targeted by the command. A
      managed  instance  can  be  an Amazon EC2 instance or an instance in
      your hybrid environment that is configured for Systems Manager.

   --plugin-name (string)
      (Optional) The name of  the  plugin  for  which  you  want  detailed
      results.  If  the document contains only one plugin, the name can be
      omitted and the details will be returned.

提前致谢。

与 运行ning AWS-RunPatchBaseline

有同样的问题

如果您查看 New-Relic_Infrastructure 文档的内容,您会注意到该文档可以执行两个操作 运行: aws:runPowerShellScript ("name": "WindowsInstallNewRelicInfrastructureAgent")aws:runShellScript ("name": "LinuxInstallNewRelicInfrastructureAgent")

所以为了获得 ssm_client.get_command_invocation 的结果,您还必须发送 PluginName="WindowsInstallNewRelicInfrastructureAgent" or "LinuxInstallNewRelicInfrastructureAgent"

问题是在您调用 ssm_client.send_command 之后,调用 get_command_invocation 将失败并显示错误

An error occurred (InvalidPluginName) when calling the GetCommandInvocation operation

你必须等到命令完成运行ning,你可以通过运行ning

检查它
# we must wait for command to finish before we query the get_command_invocation on the instance, or else the Plugins list will be empty and we will crash
keepWaiting = None
while keepWaiting is None: 
    commandResp = ssm_client.list_commands(
        CommandId=command['Command']['CommandId'] #this way we will get only this command without it crashing because it is mising the Plugin name 
    )
    if commandResp['Commands'][0]['Status'] == "InProgress" or commandResp['Commands'][0]['Status'] == "Pending":            
        time.sleep(30)
    else:
        keepWaiting = 1
    )
    

有趣的是,如果你在 powershell 中 运行:

Get-SSMCommandInvocation -CommandId 'theCommandIdYouJustGot' -Detail $true 

你会看到命令和它的状态,你可以看到 CommandPlugins 是空的,而状态是 InProgress,当状态变为 SuccessCommandPlugins 将包含两个值