def _wait_for_stack(stack_name, desired_state, wait_for, aws_config):
    conn = boto.cloudformation.connect_to_region(
        aws_config['ec2_region'],
        aws_access_key_id=aws_config['ec2_access_key'],
        aws_secret_access_key=aws_config['ec2_secret_key'])

    stack = conn.describe_stacks(stack_name)[0]

    interval_length = 10
    for interval in xrange(wait_for / interval_length):
        stack.update()
        status = stack.stack_status

        if status == desired_state:
            print()
            return
        elif status.endswith('_IN_PROGRESS'):
            sys.stdout.write('.')
            sys.stdout.flush()
            time.sleep(interval_length)
            continue
        else:
            failed_events = [
                event
                for event
                 in stack.describe_events()
                 if event.resource_status.endswith('_FAILED')
            ]
            failed_descr = ','.join([
                '{}: {}'.format(
                    event.logical_resource_id, event.resource_status_reason)
                for event
                 in failed_events
            ])
            print()
            raise Exception(
                'Stack {} did not launch successfully: {}: {}'.format(
                stack_name, status, failed_descr))
    print()
dataset/ETHPy150Open chapmanb/bcbio-nextgen-vm/bcbiovm/aws/icel.py/_wait_for_stack/original