# File lib/capazon/capistrano_plugin.rb, line 56
  def run_instance(auth,ami_id,keypair_name,group_ids=[],min_count=1,max_count=1,user_data=nil,base64_encoded=false)
    amazon = connect(auth)
    instance = amazon.run_instances(ami_id, :minCount=>min_count, :maxCount=>max_count, :keyname=>keypair_name, :groupIds=>group_ids, :userData=>user_data, :base64Encoded=>base64_encoded).parse[1]
    raise Exception, "Instance did not start" unless instance[4] == "pending"
    instance_id = instance[1]
    puts "Instance #{instance_id} Startup Pending"
    
    #loop checking for instance startup
    puts "Checking every 10 seconds to detect startup for up to 5 minutes"
    tries = 0
    begin
      instance_desc = amazon.describe_instances.parse.select { |i| i[1] == instance_id.to_s }[0]
      raise "Server Not Running" unless instance_desc[4] == "running"
      sleep 5
      return instance_desc
    rescue
      puts "."
      sleep 10
      tries += 1
      retry unless tries == 35
      raise "Server Not Running"
    end
  end