code: def wait_for_cluster_state(conn, opts, cluster_instances, cluster_state):
      
      sys.stdout.write(
          "Waiting for cluster to enter '{s}' state.".format(s=cluster_state)
      )
      sys.stdout.flush()
  
      start_time = datetime.now()
      num_attempts = 0
  
      while True:
          time.sleep(5 * num_attempts)  # seconds
  
          for i in cluster_instances:
              i.update()
  
          max_batch = 100
          statuses = []
          for j in xrange(0, len(cluster_instances), max_batch):
              batch = [i.id for i in cluster_instances[j:j + max_batch]]
              statuses.extend(conn.get_all_instance_status(instance_ids=batch))
  
          if cluster_state == 'ssh-ready':
              if all(i.state == 'running' for i in cluster_instances) and \
                 all(s.system_status.status == 'ok' for s in statuses) and \
                 all(s.instance_status.status == 'ok' for s in statuses) and \
                 is_cluster_ssh_available(cluster_instances, opts):
                  break
          else:
              if all(i.state == cluster_state for i in cluster_instances):
                  break
  
          num_attempts += 1
  
          sys.stdout.write(".")
          sys.stdout.flush()
  
      sys.stdout.write("\n")
  
      end_time = datetime.now()
      print("Cluster is now in '{s}' state. Waited {t} seconds.".format(
          s=cluster_state,
          t=(end_time - start_time).seconds
      ))
docs: Wait for all the instances in the cluster to reach a designated state.
  
      cluster_instances: a list of boto.ec2.instance.Instance
      cluster_state: a string representing the desired state of all the instances in the cluster
             value can be 'ssh-ready' or a valid value from boto.ec2.instance.InstanceState such as
             'running', 'terminated', etc.
             (would be nice to replace this with a proper enum: http://stackoverflow.com/a/1695250)