class AWS::Core::RegionCollection

Provides a mechnasim to discover available regions. This can useful if you want to perform an operation for a service in every region.

# call the EC2 DescribeInstances operation in each region
AWS.regions.each do |region|
  resp = region.ec2.client.describe_instances
end

You can also use this collection as a shortcut for creating a service interface with a given region.

s3 = AWS.regions['us-west-1'].s3

This collection enumerates and returns {Region} objects.

@see Region

Attributes

config[R]

@return [Configuration]

Public Class Methods

new(options = {}) click to toggle source

@option options [Configuration] :config (AWS.config) @option options [ServiceInterface] :service (nil) @api private

# File lib/aws/core/region_collection.rb, line 44
def initialize options = {}
  @config = options[:config] || AWS.config
  @service = options[:service]
end

Private Class Methods

clear!() click to toggle source

@return [nil] @api private

# File lib/aws/core/region_collection.rb, line 82
def clear!
  @data = nil
end
data() click to toggle source

@return [Hash] Returns a hash of region metadata. @api private

# File lib/aws/core/region_collection.rb, line 88
def data
  @data ||= load_data
end
load_data() click to toggle source

@return [Hash]

# File lib/aws/core/region_collection.rb, line 95
def load_data
  #return JSON.parse(File.read(File.join(AWS::ROOT, 'endpoints.json')))
  host = 'aws-sdk-configurations.amazonwebservices.com'
  path = '/endpoints.json'
  http = Net::HTTP
  proxy = AWS.config.proxy_uri
  http = Net::HTTP::Proxy(proxy.host, proxy.port) unless proxy.nil?
  JSON.parse(http.get(host, path))
end

Public Instance Methods

[](name) click to toggle source

@param [String] name @return [Region] Returns a {Region} with the given name.

# File lib/aws/core/region_collection.rb, line 54
def [] name
  Region.new(name, :config => config)
end
each() { |self| ... } click to toggle source

Enumerates public regions (non US Gov regions). @yieldparam [region] Region

# File lib/aws/core/region_collection.rb, line 60
def each &block
  public_regions.each do |region_name|
    yield(self[region_name])
  end
end

Private Instance Methods

public_regions() click to toggle source

@return [Array<String>] Returns an array of non-gov-cloud region names.

# File lib/aws/core/region_collection.rb, line 69
def public_regions
  return ['us-east-1'] if @service and @service.global_endpoint?
  data = self.class.data
  regions = @service ?
    data['services'][@service.endpoint_prefix] :
    data['regions'].keys
  regions.reject{|r| r =~ /us-gov/ }
end