Skip to main content
 首页 » 编程设计

python之从 boto 运行私有(private) AMI ec2 实例

2025年05月04日9zhwl

两天来我一直在寻找问题的解决方案,但我没有任何迹象表明我在使用 boto 将私有(private) AMI 作为 EC2 实例运行时做错了什么。我没有看到任何页面清楚地解释如何去做,也没有看到任何人遇到我的问题。

为了更清楚地解释我的问题:

  • 我已经在 Web 界面上创建了一个自定义 AMI(安装了一些包,添加了一些文件)

  • 现在我想在我的计算机上使用 Python 脚本自动执行我在 AMI 上执行的任务(如果可能,运行这个特定 AMI 的多个实例)

  • 我编写了以下示例代码:

    import boto.ec2 
     
    conn = boto.ec2.connect_to_region("eu-west-1", 
      aws_access_key_id='myAKI',aws_secret_access_key='MySK') 
     
    print (conn) 
     
    reservation=conn.run_instances(image_id='ami-XXXXX', 
      instance_type='m1.small',key_name='MyKey') 
    

当我运行这段代码时出现错误:

EC2Connection:ec2.eu-west-1.amazonaws.com 
Traceback (most recent call last): 
  File "./myfile.py", line 6, in <module> 
    reservation=conn.run_instances(image_id='ami-  XXXX',instance_type='m1.small',key_name='MyKey') 
  File "/Library/Python/2.7/site-packages/boto-2.8.0-py2.7.egg/boto/ec2/connection.py", line 722, in run_instances 
verb='POST') 
  File "/Library/Python/2.7/site-packages/boto-2.8.0-py2.7.egg/boto/connection.py", line   1062, in get_object 
    raise self.ResponseError(response.status, response.reason, body) 
boto.exception.EC2ResponseError: EC2ResponseError: 400 Bad Request 
<?xml version="1.0" encoding="UTF-8"?> 
<Response><Errors><Error><Code>AuthFailure</Code><Message>Not authorized for images: [ami- XXXXXXX]</Message></Error></Errors><RequestID>6b653488-332d-4251-abb2-8e7e96e91891</RequestID>    </Response> 

有人知道如何进行吗?我假设可能存在连接问题,但我可以获得公共(public)图像列表。我不知道如何进一步调试。

请您参考如下方法:

我认为它试图告诉您与您的 EC2 连接相关联的帐户凭据无权访问 AMI。也许它是用不同的帐户创建的?