python - 无效的实例 ID : An error occurred (InvalidInstanceId) when calling the SendCommand operation

标签 python amazon-web-services amazon-ec2 boto3

以下是我从 python 运行以在 aws ec2 实例中执行命令的代码

import boto3
ec2 = boto3.client('ssm',region_name='us-east-1',aws_access_key_id='xxxxxxxxxxxxxxx',aws_secret_access_key='xxxxxxxxx')
a = ec2.send_command(InstanceIds=ids, DocumentName='AWS-RunShellScript', Comment='abcdabcd', Parameters={"commands":["ifconfig"]})

但它给出了以下错误

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

最佳答案

以下情况可能会导致此错误消息:

  • 实例 ID 无效(在评论中您已验证它不是)
  • 实例位于不同的区域(在评论中您已验证它不是)
  • 实例当前未处于Running状态
  • 实例没有 AWS SSM agent安装并运行。

您需要登录 AWS EC2/SSM 控制台并确保您尝试管理的实例显示在SYSTEMS MANAGER SHARED RESOURCES - Managed Instances 列表,并且它们显示 Ping 状态 在线。如果不是,您需要在尝试向相关实例发送命令之前解决该问题。

关于python - 无效的实例 ID : An error occurred (InvalidInstanceId) when calling the SendCommand operation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47034797/

相关文章:

python:文件 i/o 计算没有换行的字符

python - 如何保存<ipython.core.display.image对象>

python - CCKeyDerivationPBKDF 线程安全吗?

amazon-web-services - 如何在没有pem文件的情况下在aws ec2实例中部署maven项目

amazon-web-services - AWS S3 存储桶策略

ruby-on-rails - Sidekiq 日志级别未在生产中设置

amazon-ec2 - 如何在 Amazon EC2 实例上增加 ulimit?

python - 无法将文件上传到 Google 云端硬盘

amazon-web-services - AWS 多区域 VPC 中的 Cassandra 集群

amazon-web-services - 使用 Route 53 将特定路径路由到特定 EC2 实例