You are viewing documentation for version 1 of the AWS SDK for Ruby. Version 2 documentation can be found here.

Class: AWS::EC2::Region

Inherits:
Object
  • Object
show all
Defined in:
lib/aws/ec2/region.rb

Overview

Represents an EC2 region. You can use this to find the endpoint for a given region:

ec2.regions["us-west-1"].endpoint

Region also responds to all of the methods of AWS::EC2 except #regions; for example, to list instance IDs by region, you can do:

ec2.regions.inject({}) do |h,region|
  h[region.name] = region.instances.map(&:id)
  h
end

Constant Summary

PROXIED_METHODS =
[
  :instances,
  :security_groups,
  :key_pairs,
  :elastic_ips,
  :tags,
  :availability_zones,
  :images,
  :volumes,
  :snapshots,
  :reserved_instances,
  :reserved_instances_offerings,
  :vpcs,
  :subnets,
  :network_acls,
  :route_tables,
  :network_interfaces,
  :internet_gateways,
  :customer_gateways,
  :vpn_gateways,
  :dhcp_options,
  :vpn_connections,
  :export_tasks,
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ Region

Returns a new instance of Region



36
37
38
39
40
41
# File 'lib/aws/ec2/region.rb', line 36

def initialize name, options = {}
  @name = name
  @endpoint = options[:endpoint] || "ec2.#{name}.amazonaws.com"
  @client = Client.new(options.merge(:endpoint => endpoint))
  @config = @client.config
end

Instance Attribute Details

#clientClient (readonly)

Returns:



50
51
52
# File 'lib/aws/ec2/region.rb', line 50

def client
  @client
end

#configCore::Configuration (readonly)

Returns:



53
54
55
# File 'lib/aws/ec2/region.rb', line 53

def config
  @config
end

#endpointString (readonly)

Returns:

  • (String)


34
35
36
# File 'lib/aws/ec2/region.rb', line 34

def endpoint
  @endpoint
end

#nameString (readonly)

Returns The name of the region (e.g. "us-west-2").

Returns:

  • (String)

    The name of the region (e.g. "us-west-2").



44
45
46
# File 'lib/aws/ec2/region.rb', line 44

def name
  @name
end

Instance Method Details

#eql?(other) ⇒ Boolean Also known as: ==

Parameters:

Returns:

  • (Boolean)


66
67
68
69
70
# File 'lib/aws/ec2/region.rb', line 66

def eql? other
  other.is_a?(Region) and
  other.name == name and
  other.endpoint == endpoint
end

#exists?Boolean

Returns True if the region is available for this account.

Returns:

  • (Boolean)

    True if the region is available for this account.



57
58
59
60
61
62
# File 'lib/aws/ec2/region.rb', line 57

def exists?
  client.describe_regions(:region_names => [name])
  true
rescue Errors::InvalidParameterValue
  false
end