2016-07-01 12 views
0

インスタンスを停止しようとしていますが、インスタンスのリストを開始しようとしています。インスタンスオブジェクト変数が更新されていないため、インスタンスを開始できませんでした。boto3

Inside the STOP while LOOP 
Instance is still being Stopped 
Inside the STOP while LOOP 
Instance is still being Stopped 
. 
. 
. 
. 
<to_infinity> 

これは、あなたがそこにsleepを追加したい場合があります非常に忙しいループです

答えて

1

助けてください:これは印刷を続けている

client = boto3.client('ec2', aws_access_key_id=ACCESS_KEY, aws_secret_access_key=SECRET_KEY, region_name=region,) 
response = client.stop_instances(InstanceIds=[instance_id]) 
print "Stopping instance Now",response['StoppingInstances'] 

for instance in response['StoppingInstances']: 
    while instance['CurrentState']['Name'] != "stopped": 
     print "Inside the STOP while LOOP" 
     if instance['CurrentState']['Name'] == "stopped": 
      print "Now instance is Stopped!!!" 
     else : 
      print "Instance is still being Stopped" 

よう

コードが見えます。
ステータスを更新するのではなく、毎回同じステータスを参照するだけで、最新のステータスを取得する必要があります。あなたが使用することができ、その後停止するインスタンスのリストを待っている場合は

ec2 = boto3.resource('ec2') 
response = ec2.Instance(instance_id).stop() 

while ec2.Instance(instance_id).state['Name'] != "stopped": 
    print "Instance is still being Stopped" 
    time.sleep(5) 
else: 
    print "Now instance is Stopped!!!" 

:あなただけの、あなたが行うことができ、単一のinstance_idを停止している与えられた

ec2 = boto3.resource('ec2') 
response = ec2.instances.filter(InstanceIds=instance_ids).stop() 

while all(i.state['Name'] != 'stopped' for i in ec2.instances.filter(InstanceIds=instance_ids)): 
    print "Instances are still being Stopped" 
    time.sleep(5) 
else: 
    print "All instances are Stopped!!!" 
+0

大丈夫、私が実際にリストを渡しています一度これらのインスタンスが停止すると、実際にそれらを開始する必要があるので、私はstopを 'start()'に変更すれば十分でしょうか? – Kittystone

+0

はい、 'start()' – AChampion

+0

ですべてのインスタンスを起動できます。この 'AttributeError: 'ec2.Instance'オブジェクトには属性 'status''がありません – Kittystone

関連する問題