Skip to content

Regions#224

Merged
lsegal merged 5 commits into
masterfrom
regions
Apr 12, 2013
Merged

Regions#224
lsegal merged 5 commits into
masterfrom
regions

Conversation

@trevorrowe
Copy link
Copy Markdown
Contributor

Improved support for working regions.

Configuring a Default region

AWS.config now accepts a :region option (defaults to 'us-east-1'). You can set this value globally or on a per service/client.

# set a new default region
AWS.config(:region => 'us-west-2')

# override the default region 
ec2 = AWS::EC2.new(:region => 'us-west-1')

Region and RegionCollection

You can now also use the new regions interface to get service objects:

ddb = AWS.regions['us-west-2'].dynamo_db
ddb.tables.map(&:name)

The regions collection object is enumerable as well:

AWS.regions.each.map(&:name)

You can access a region collection from service classes. These will only enumerate the regions the service operates in.

# get a full list of dynamo db tables, grouped by region
AWS::DynamoDB.regions.each do |region|
  puts region.name
  puts region.dynamo_db.tables.map(&:name)
  puts ''
end

The old style endpoint configuration options are still supported. These should be considered deprecated and will likely be removed in the next major version (2.0).

You can now specify what AWS region you want to connect to:

    AWS.config(:region => 'us-west-2')

The individual configuration options for each service endpoints are
now deprecated.  If you want to override the endpoint for a service
you can do so in the constructor:

    AWS::S3.new(:region => 'us-east-1')

    # this also works
    AWS::S3.new(:endpoint => 's3-us-east-1.amazonaws.com')

Documentation changes were made to remove mention of the now
deprecated options.
You can get a region object using AWS.regions.  This region
can be used as a shortcut for getting region specific clients.

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

    east.ec2.instances.map(&:id)
    west.ec2.instances.map(&:id)

You can also explore available regions using AWS.regions:

    # makes a single (cached) http request to get a complete list of regions
    AWS.regions.each do |region|
      puts region.name
    end
You can now enumerate the regions a specific service
is available in.

    # generate a list of tables per region
    AWS::DynamoDB.regions.each do |region|
      puts regions.name
      puts region.dynamo_db.tables.map(&:name)
      puts ''
    end
lsegal added a commit that referenced this pull request Apr 12, 2013
Add support for specifying regions, deprecate :SVC_endpoint option
@lsegal lsegal merged commit d72b8dd into master Apr 12, 2013
@lsegal lsegal deleted the regions branch April 12, 2013 17:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants