1

所以我试图让所有实例通过 python 检查它们的状态。

我在这里找到了一个有人建议的脚本,看起来像这样:

from boto.ec2.connection import EC2Connection

conn = EC2Connection('MY Key ID', 'Secret Access Key')

reservations = conn.get_all_instances()
instance = reservations.instances[0]
print instance.status

但是,每次我运行它时,我都会收到如下错误:

File "/usr/lib/python2.7/dist-packages/boto/ec2/connection.py", line 466, in get_all_instances
, verb='POST')
File "/usr/lib/python2.7/dist-packages/boto/connection.py", line 882, in get_list
response = self.make_request(action, params, path, verb)
File "/usr/lib/python2.7/dist-packages/boto/connection.py", line 868, in make_request
return self._mexe(http_request)
File "/usr/lib/python2.7/dist-packages/boto/connection.py", line 794, in _mexe
raise e
socket.gaierror: Errno -2 Name or service not known
4

2 回答 2

1

与其直接构造 EC2Connection 对象,不如尝试以下方法:

import boto.ec2
conn = boto.ec2.connect_to_region('us-east-1',
                                  aws_access_key_id='<access_key>',
                                  aws_secret_access_key='<secret_key>')

reservations = conn.get_all_instances()
instances = [i for r in reservations for i in r.instances]
for instance in instances:
    print instance.id, instance.state

那对你有用吗?

于 2013-01-23T20:54:25.207 回答
0

boto--- 文档实际上告诉您使用 AWS CLI 工具来执行凭证

特别是这篇文章:https ://boto3.readthedocs.io/en/latest/guide/quickstart.html

    If you have the AWS CLI installed, 
 then you can use it to configure your credentials file:   aws configure

希望能帮助到你

于 2017-05-09T16:17:12.470 回答