도와주세요 : 이것은 인쇄에 유지
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!!!"
좋아, 실제로 목록을 통과하고 예를 들어, 일단 이러한 인스턴스가 실제로 그들을뿐만 아니라 시작해야 중지되었습니다, 그래서 만약 내가'stop()'중지를 변경하면 충분합니까? – Kittystone
예'start()' – AChampion
으로 모든 인스턴스를 시작할 수 있습니다.이 'AttributeError :'ec2.Instance '객체에'status '속성이 없습니다. – Kittystone