Class: AWS::ELB::LoadBalancerCollection

Inherits:
Object
  • Object
show all
Includes:
Core::Collection::Simple, ListenerOpts
Defined in:
lib/aws/elb/load_balancer_collection.rb

Instance Attribute Summary

Attributes included from Core::Model

#config

Instance Method Summary collapse

Methods included from Core::Collection::Simple

#each_batch

Methods included from Core::Collection

#each, #each_batch, #enum, #first, #in_groups_of, #page

Methods included from Core::Model

#client, #config_prefix, #initialize, #inspect

Instance Method Details

#[](name) ⇒ LoadBalancer

Returns the load balancer with the given name. This does not make a request, just returns a reference.

Returns:

  • (LoadBalancer)

    Returns the load balancer with the given name. This does not make a request, just returns a reference.



91
92
93
# File 'lib/aws/elb/load_balancer_collection.rb', line 91

def [] name
  LoadBalancer.new(name, :config => config)
end

#create(name, options = {}) ⇒ Object

Creates and returns a load balancer. A load balancer requires:

  • a unique name

  • at least one availability zone

  • at least one listener

An example that creates a load balancer in two availability zones with a single listener:

load_balancer = elb.load_balancers.create('my-load-balancer',
  :availability_zones => %w(us-east-1a us-east-1b),
  :listeners => [{
    :port => 80,
    :protocol => :http,
    :instance_port => 80,
    :instance_protocol => :http,
  }])

Parameters:

  • name (String)

    The name of your load balancer. The name must be unique within your set of load balancers.

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :availability_zones (required, Array)

    An array of one or more availability zones. Values may be availability zone name strings, or AWS::EC2::AvailabilityZone objects.

  • :listeners (required, Array)

    An array of load balancer listener options. Each value must be an array with the following keys:

    :port :protocol :instance_port :instance_protocol

    Port values should be integers, and protocols should be symbols or strings (e.g. :http, or ‘HTTP’). See AWS::ELB::ListenerCollection#create for more detailed description of each option.

  • :server_certificate (String, IAM::ServerCertificate) — default: nil

    The ARN string of an IAM::ServerCertifcate or an IAM::ServerCertificate object. Reqruied for HTTPs listeners.



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/aws/elb/load_balancer_collection.rb', line 66

def create name, options = {}
  
  zones = [options[:availability_zones]].flatten.collect do |zone|
    zone.is_a?(EC2::AvailabilityZone) ? zone.name : zone
  end

  listeners = [options[:listeners]].flatten.collect do |listener_opts|
    format_listener_opts(listener_opts)
  end

  response = client.create_load_balancer(
    :load_balancer_name => name.to_s,
    :availability_zones => zones,
    :listeners => listeners)

  opts = {}
  opts[:config] = config
  opts[:dns_name] = response.dns_name

  LoadBalancer.new(name, opts)

end