10

インスタンスIDでインスタンスを取得する必要がありますが、すべてのインスタンスのリストを要求せずに取得することは可能ですか?

私はもう試した:

ec2_conn = boto.connect_ec2(aws_access_key_id=key, aws_secret_access_key=access)
c2.get_all_instances([instanceId])

それは機能しますが、インスタンスを取得する他の方法はありますか?

私が尋ねている理由は、私がリクエストを受け取っUnauthorizedOperationget_all_instancesので、セキュリティ設定ではなく、リクエストを変更したいと思います。

4

3 に答える 3

16

botoOPが質問した時から進化したのかもしれませんが、これは最新の回答をここに追加する価値があります:

reservations = ec2conn.get_all_instances(instance_ids=['i-12345678'])
instance = reservations[0].instances[0]
于 2013-04-25T16:23:37.800 に答える
8

あなたはで試すことができます

reservations = ec2_conn.get_all_instances(filters={'instance-id' : 'i-xxxxxxxx'})
new_instance = reservations[0].instances[0]

それは間違いなく機能します。

于 2012-08-24T13:12:22.663 に答える
3
instances = get_only_instances(instance_ids=['i-12345678'])

上記の回答について

get_all_instances()

BOTO APIから--

get_all_instances() is deprecated in favor of get_all_reservations(). 

A future major release will change get_all_instances() to return a list of 
boto.ec2.instance.Instance objects as its name suggests. 
To obtain that behavior today, use get_only_instances().
于 2015-04-16T20:35:19.193 に答える