2016-07-01 4 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()'중지를 변경하면 충분합니까? – Kittystone

+0

예'start()' – AChampion

+0

으로 모든 인스턴스를 시작할 수 있습니다.이 'AttributeError :'ec2.Instance '객체에'status '속성이 없습니다. – Kittystone

관련 문제