code: def wait_for_instance(instance):
      
  
      status = None
      print("getting status for instance {} ...".format(instance.id))
      while status is None:
          try:
              status = instance.update()
              if status is None:
                  time.sleep(2)
          except EC2ResponseError:
              time.sleep(2)
  
      print("waiting for instance {} ...".format(instance.id))
  
      while status == "pending":
          time.sleep(2)
          status = instance.update()
  
      if status != "running":
          print("Invalid status when starting instance {}: {}".format(instance.id, status))
          return False
  
      print("New instance {} started: {}".format(instance.id, instance.ip_address))
      return True
docs: wait for instance status to be 'running' in which case return True, False otherwise