我已经能够成功将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-namecorrectName来获取状态。
我知道send_command正在使用此文档。我也知道commandID。
我已经在实例以及在适用于Systems Manager的AWS CLI中-> Run Command界面中看到了结果。
现在,我正在尝试通过get-command-invocation检索命令状态。我的AWS CLI命令:
aws ssm get-command-invocation --command-id 28XXXa35-dXX1-4XX1-9XX0-9ecfXXXX29ae --instance-id i-0c038XXXXc4e9c66e
我收到此回复:
调用GetCommandInvocation操作时发生错误(InvalidPluginName):
我也尝试过:
aws ssm get-command-invocation --command-id 28XXXa35-dXX1-4XX1-9XX0-9ecfXXXX29ae --instance-id i-0c038XXXXc4e9c66e --plugin-name runShellScript
具有完全相同的响应。
关于为什么我在可选插件时收到无效插件错误的任何想法?
来自:aws ssm get-command-invocation帮助
概要
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>]
选项
--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.
提前致谢。
跑步也有同样的问题 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
会因错误而失败
调用GetCommandInvocation操作时发生错误(InvalidPluginName)
您必须等到命令完成运行,然后才能通过运行对其进行检查
# 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
,当状态变为Success
了CommandPlugins
将包含两个值
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句