You are viewing documentation for version 1 of the AWS SDK for Ruby. Version 2 documentation can be found here.
Class: AWS::ELB::LoadBalancerCollection
- Inherits:
-
Object
- Object
- AWS::ELB::LoadBalancerCollection
- Includes:
- Core::Collection::WithNextToken
- Defined in:
- lib/aws/elb/load_balancer_collection.rb
Instance Method Summary collapse
-
#[](name) ⇒ LoadBalancer
Returns the load balancer with the given name.
-
#create(name, options = {}) ⇒ Object
Creates and returns a load balancer.
Methods included from Core::Collection
#each, #each_batch, #enum, #first, #in_groups_of, #page
Instance Method Details
#[](name) ⇒ LoadBalancer
Returns the load balancer with the given name. This does not make a request, just returns a reference.
124 125 126 |
# File 'lib/aws/elb/load_balancer_collection.rb', line 124 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-west-2a us-west-2b),
:listeners => [{
:port => 80,
:protocol => :http,
:instance_port => 80,
:instance_protocol => :http,
}])
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/aws/elb/load_balancer_collection.rb', line 88 def create name, = {} if listeners = [:listeners] [:listeners] = [listeners].flatten.map do |listener| format_listener_opts(listener) end end if zones = [:availability_zones] [:availability_zones] = [zones].flatten.map do |zone| zone.is_a?(EC2::AvailabilityZone) ? zone.name : zone end end if groups = [:security_groups] [:security_groups] = [groups].flatten.map do |group| group.is_a?(EC2::SecurityGroup) ? group.id : group end end if subnets = [:subnets] [:subnets] = [subnets].flatten.map do |subnet| subnet.is_a?(EC2::Subnet) ? subnet.id : subnet end end [:load_balancer_name] = name.to_s resp = client.create_load_balancer() LoadBalancer.new(name, :dns_name => resp[:dns_name], :config => config) end |