相关疑难解决方法(0)

SSM发送命令到EC2实例失败

我正在尝试使用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"]})
Run Code Online (Sandbox Code Playgroud)

输出:

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: 
Run Code Online (Sandbox Code Playgroud)

如果我正在尝试用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 …
Run Code Online (Sandbox Code Playgroud)

python instances amazon-web-services ssm

9
推荐指数
2
解决办法
1万
查看次数

如何使用 AWS CLI 在多个 EC2 实例上运行 shell 脚本?

我正在尝试执行一个简单的 AWS CLI 命令,该命令可以对多个实例运行 shell 命令。

我知道首先我需要获取实例 ID 列表:

aws ec2 describe-instances --filter "Name=tag:Group,Values=Development" --query 'Reservations[].Instances[].[InstanceId]' --output text
Run Code Online (Sandbox Code Playgroud)

然后我将不得不将它们分配给一个数组。然后遍历每个实例 ID 并发送命令。

我们是否可以选择让 aws 将 shell 命令发送到具有特定 ID 的实例?

像这样的东西:

aws ssm send-command --instance-ids "i-xxxxxxxxxxxxxxxx" --document-name "shellscript"
Run Code Online (Sandbox Code Playgroud)

我不断收到此错误:

调用 SendCommand 操作时发生错误 (InvalidInstanceId):

我已确保 SSM 代理在该特定实例上运行,并根据这些文档页面确保一切正确。

shell amazon-web-services

2
推荐指数
1
解决办法
3564
查看次数

标签 统计

amazon-web-services ×2

instances ×1

python ×1

shell ×1

ssm ×1