# File lib/deltacloud/drivers/ec2/ec2_driver.rb, line 196
        def create_instance(credentials, image_id, opts={})
          ec2 = new_client(credentials)
          instance_options = {}
          instance_options.merge!(:user_data => opts[:user_data]) if opts[:user_data]
          instance_options.merge!(:key_name => opts[:keyname]) if opts[:keyname]
          instance_options.merge!(:availability_zone => opts[:realm_id]) if opts[:realm_id]
          instance_options.merge!(:instance_type => opts[:hwp_id]) if opts[:hwp_id] && opts[:hwp_id].length > 0
          instance_options.merge!(:group_ids => opts[:security_group]) if opts[:security_group]
          instance_options.merge!(
            :min_count => opts[:instance_count],
            :max_count => opts[:instance_count]
          ) if opts[:instance_count] and opts[:instance_count].length!=0
          safely do
            new_instance = convert_instance(ec2.launch_instances(image_id, instance_options).first)
            # TODO: Rework this to use client_id for name instead of tag
            #       Tags should be keept as an optional feature
            tag_instance(credentials, new_instance, opts[:name])
            # Register Instance to Load Balancer if load_balancer_id is set.
            # This parameter is a feature parameter
            if opts[:load_balancer_id] and opts[:load_balancer_id]!=""
              lb = lb_register_instance(credentials,
                                        {'id' => opts[:load_balancer_id],
                                         'instance_id' => new_instance.id})
            end
            new_instance
          end
        end