'Wait for an ELB to change state
lb: load balancer
awaited_state : state to poll for (string)'

def _await_elb_instance_state(self, lb, awaited_state, initial_state, timeout):

    wait_timeout = (time.time() + timeout)
    while True:
        instance_state = self._get_instance_health(lb)
        if (not instance_state):
            msg = 'The    instance    %s    could    not    be    put    in    service    on    %s.    Reason:    Invalid    Instance'
            self.module.fail_json(msg=(msg % (self.instance_id, lb)))
        if (instance_state.state == awaited_state):
            if ((initial_state is None) or (instance_state.state != initial_state.state)):
                self.changed = True
            break
        elif self._is_instance_state_pending(instance_state):
            pass
        elif ((awaited_state == 'InService') and (instance_state.reason_code == 'Instance') and (time.time() >= wait_timeout)):
            msg = 'The    instance    %s    could    not    be    put    in    service    on    %s.    Reason:    %s'
            self.module.fail_json(msg=(msg % (self.instance_id, lb, instance_state.description)))
        time.sleep(1)
