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 に答える