gpt4 book ai didi

python - SSM 向 EC2 实例发送命令失败

转载 作者:太空狗 更新时间:2023-10-29 20:13:34 34 4
gpt4 key购买 nike

我正在尝试使用 boto3 在 EC2 实例上运行 ssh 命令。我阅读了本指南: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/troubleshooting-remote-commands.html我做了他们在那里写的所有内容,但我不断收到错误消息:

>>>import boto3
>>> ec2 = boto3.client('ssm')
>>> a = ec2.send_command(InstanceIds=['i-0d5e16f6'], DocumentName='AWS-RunShellScript', Comment='abcdabcd', Parameters={"commands":["ifconfig"]})

输出:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/botocore/client.py", line 253, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/usr/local/lib/python2.7/dist-packages/botocore/client.py", line 543, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.errorfactory.InvalidInstanceId: An error occurred (InvalidInstanceId) when calling the SendCommand operation:

如果我尝试使用 awscli 发送命令,我会遇到同样的问题:

aws ssm send-command --instance-ids "i-0d5e16f6" --document-name "AWS-RunShellScript" --comment "IP config" --parameters commands=ifconfig --output text

An error occurred (InvalidInstanceId) when calling the SendCommand operation:

有人知道怎么解决吗?

最佳答案

当您没有 SSM agent 时可能会发生这种情况安装在您尝试访问的实例上。要获取可以运行 SSM 命令的实例列表,请运行:

aws ssm describe-instance-information --output text

从那里,您可以获取一个实例 ID,然后对该实例运行 send_command 命令。

关于python - SSM 向 EC2 实例发送命令失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42279963/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com