Parent

Files

RightAws::Route53Interface

RightAws::Route53Interface -- Amazon Route 53 web service interface.

The RightAws::Route53Interface class provides a complete interface to Amazon Route 53: a web service that enables you to manage your DNS service.

For explanations of the semantics of each call, please refer to Amazon's documentation at aws.amazon.com/documentation/route53/

Examples:

# Create Route53 handler
r53 = RightAws::Route53Interface.new(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)

#------------------------
# Create Hosted Zone
#------------------------

hosted_zone_config = {
  :name   => 'my-awesome-site.com.',
  :config => {
    :comment => 'My test site!'
   }
}
r53.create_hosted_zone(hosted_zone_config) #=>
  {:name_servers=>
    ["ns-1115.awsdns-11.org",
     "ns-696.awsdns-23.net",
     "ns-1963.awsdns-53.co.uk",
     "ns-362.awsdns-45.com"],
   :aws_id=>"/hostedzone/Z1K6NCF0EB26FB",
   :caller_reference=>"1295424990-710392-gqMuw-KcY8F-LFlrB-SQhp9",
   :config=>{:comment=>"My test site!"},
   :change_info=>
    {:status=>"PENDING",
     :aws_id=>"/change/C23QGMT8XTCAJY",
     :submitted_at=>"2011-01-19T08:16:31.046Z"},
   :name=>"my-awesome-site.com."}

# List Hosted Zones
r53.list_hosted_zones #=> []
  [{:aws_id=>"/hostedzone/Z1K6NCF0EB26FB",
    :caller_reference=>"1295424990-710392-gqMuw-KcY8F-LFlrB-SQhp9",
    :config=>{:comment=>"My test site!"},
    :name=>"my-awesome-site.com."}]

#--------------------------------
# Manage DNS Records and Changes
#--------------------------------

# Create DNS Records
resource_record_sets = [ { :name => 'www1.my-awesome-site.com.',
                           :type => 'NS',
                           :ttl => 600,
                           :resource_records => 'www.mysite.com' },
                         { :name => 'www2.my-awesome-site.com.',
                           :type => 'A',
                           :ttl => 600,
                           :resource_records => ['10.0.0.1'] } ]
r53.create_resource_record_sets("/hostedzone/Z1K6NCF0EB26FB", resource_record_sets, 'my first set of records') #=>
  { :status=>"PENDING",
    :aws_id=>"/change/C2C6IGNRTKA0AY",
    :submitted_at=>"2011-01-19T08:29:26.160Z" }

# Delete DNS records
r53.delete_resource_record_sets("/hostedzone/Z1K6NCF0EB26FB", resource_record_sets, 'I dont need them any more') #=>
  { :status=>"PENDING",
    :aws_id=>"/change/C1CYJ10EZBFLO7",
    :submitted_at=>"2011-01-19T08:26:41.220Z" }

# Create or delete DNS records (:action key must be provided):
resource_record_sets = [ { :action => :create,
                           :name => 'www1.my-awesome-site.com.',
                           :type => 'NS',
                           :ttl => 600,
                           :resource_records => 'www.mysite.com' },
                         { :action => :delete,
                           :name => 'www2.my-awesome-site.com.',
                           :type => 'A',
                           :ttl => 600,
                           :resource_records => ['10.0.0.1'] } ]
r53.change_resource_record_sets("/hostedzone/Z1K6NCF0EB26FB", resource_record_sets, 'do change records')
  { :status=>"PENDING",
    :aws_id=>"/change/C2PWXVECN794LK",
    :submitted_at=>"2011-01-19T08:31:33.301Z" }

# List DNS Records
r53.list_resource_record_sets("/hostedzone/Z1K6NCF0EB26FB") #=>
  [{:type=>"NS",
    :ttl=>172800,
    :resource_records=>
     ["ns-1115.awsdns-11.org.",
      "ns-696.awsdns-23.net.",
      "ns-1963.awsdns-53.co.uk.",
      "ns-362.awsdns-45.com."],
    :name=>"my-awesome-site.com."},
   {:type=>"SOA",
    :ttl=>900,
    :resource_records=>
     ["ns-1115.awsdns-11.org. awsdns-hostmaster.amazon.com. 1 7200 900 1209600 86400"],
    :name=>"my-awesome-site.com."},
   {:type=>"NS",
    :ttl=>600,
    :resource_records=>["www.mysite.com"],
    :name=>"www1.my-awesome-site.com."}]

# Get Change info
r53.get_change("/change/C2C6IGNRTKA0AY")
  {:status=>"INSYNC",
   :aws_id=>"/change/C2C6IGNRTKA0AY",
   :submitted_at=>"2011-01-19T08:29:26.160Z"}

#------------------------
# Delete Hosted Zone
#------------------------

# Get a list of DNS records I have created (the first 2 records were added by Amazon and cannot be deleted)
resource_record_sets = r53.list_resource_record_sets("/hostedzone/Z1K6NCF0EB26FB")
resource_record_sets.shift
resource_record_sets.shift

# Delete them all
delete_resource_record_sets("/hostedzone/Z1K6NCF0EB26FB", resource_record_sets, 'kill all records I have created') #=>
  { :status=>"PENDING",
    :aws_id=>"/change/C6NCO8Z50MHXV",
    :submitted_at=>"2011-01-19T08:46:37.307Z" }

# Delete Hosted Zone
r53.delete_hosted_zone("/hostedzone/Z1K6NCF0EB26FB") #=> 
  { :status=>"PENDING",
    :aws_id=>"/change/C3OJ31D4V5P2LU",
    :submitted_at=>"2011-01-19T08:46:37.530Z" }

Public Class Methods

bench_service() click to toggle source
# File lib/route_53/right_route_53_interface.rb, line 171
def self.bench_service
  @@bench.service
end
bench_xml() click to toggle source
# File lib/route_53/right_route_53_interface.rb, line 168
def self.bench_xml
  @@bench.xml
end
new(aws_access_key_id=nil, aws_secret_access_key=nil, params={}) click to toggle source

Create a new handle to an Route53 account. All handles share the same per process or per thread HTTP connection to Amazon Route53. Each handle is for a specific account. The params have the following options:

  • :endpoint_url a fully qualified url to Amazon API endpoint (this overwrites: :server, :port, :service, :protocol).

  • :server: Route53 service host, default: DEFAULT_HOST

  • :port: Route53 service port, default: DEFAULT_PORT

  • :protocol: 'http' or 'https', default: DEFAULT_PROTOCOL

  • :logger: for log messages, default: RAILS_DEFAULT_LOGGER else STDOUT

  • :signature_version: The signature version : '0','1' or '2'(default)

# File lib/route_53/right_route_53_interface.rb, line 185
def initialize(aws_access_key_id=nil, aws_secret_access_key=nil, params={})
  init({ :name                => 'ROUTE_53',
         :default_host        => ENV['ROUTE_53_URL'] ? URI.parse(ENV['ROUTE_53_URL']).host   : DEFAULT_HOST,
         :default_port        => ENV['ROUTE_53_URL'] ? URI.parse(ENV['ROUTE_53_URL']).port   : DEFAULT_PORT,
         :default_service     => ENV['ROUTE_53_URL'] ? URI.parse(ENV['ROUTE_53_URL']).path   : DEFAULT_PATH,
         :default_protocol    => ENV['ROUTE_53_URL'] ? URI.parse(ENV['ROUTE_53_URL']).scheme : DEFAULT_PROTOCOL,
         :default_api_version => ENV['ROUTE_53_API_VERSION'] || API_VERSION },
       aws_access_key_id    || ENV['AWS_ACCESS_KEY_ID'] ,
       aws_secret_access_key|| ENV['AWS_SECRET_ACCESS_KEY'],
       params)
end

Public Instance Methods

change_resource_record_sets(hosted_zone_aws_id, resource_record_sets, comment = '') click to toggle source

Create or delete DNS records.

resource_record_sets = [{ :action => :create,
                          :name => 'm3.mysite.patch-island.com',
                          :type => 'NS',
                          :ttl => 600,
                          :resource_records => 'xxx.mysite.com' },
                        { :action => :delete,
                          :name => 'm2.mysite.patch-island.com',
                          :type => 'A',
                          :ttl => 600,
                          :resource_records => ['10.0.0.1'] }]
r53.change_resource_record_sets("/hostedzone/Z1K6NCF0EB26FB", resource_record_sets, 'KD: Comment#1') #=>
  {:status=>"PENDING",
   :submitted_at=>"2011-01-18T20:21:56.828Z",
   :aws_id=>"/change/C394PNLM1B2P08"}

PS: resource_record_sets must have an :action key set (== :create or :delete) PPS: docs.amazonwebservices.com/Route53/latest/APIReference/API_ChangeResourceRecordSets.html

# File lib/route_53/right_route_53_interface.rb, line 481
def change_resource_record_sets(hosted_zone_aws_id, resource_record_sets, comment = '')
  link = generate_request('POST', "#{expand_hosted_zone_id(hosted_zone_aws_id)}/rrset", {}, resource_record_sets_to_xml(resource_record_sets, comment))
  request_info(link, GetChangeParser.new(:logger => @logger))
end
create_hosted_zone(config) click to toggle source

Create new hosted zone

config = {
  :name => 'mysite.patch-island.com.',
  :config => {
    :comment => 'My awesome site!'
   }
}
r53.create_hosted_zone(config) #=>
  {:config=>{:comment=>"My awesome site!"},
   :change_info=>
    {:status=>"PENDING",
     :aws_id=>"/change/C2NOTVGL7IOFFF",
     :submitted_at=>"2011-01-18T15:34:18.086Z"},
   :aws_id=>"/hostedzone/ZWEC7PPVACGQ4",
   :caller_reference=>"1295365357-227168-NfZ4P-VGHWi-Yq0p7-nuN6q",
   :name_servers=>
    ["ns-794.awsdns-35.net",
     "ns-459.awsdns-57.com",
     "ns-1537.awsdns-00.co.uk",
     "ns-1165.awsdns-17.org"],
   :name=>"mysite.patch-island.com."}

PS: docs.amazonwebservices.com/Route53/latest/APIReference/index.html?API_CreateHostedZone.html

# File lib/route_53/right_route_53_interface.rb, line 383
def create_hosted_zone(config)
  config[:caller_reference] ||= AwsUtils::generate_unique_token
  link = generate_request('POST', 'hostedzone', {}, hosted_zone_config_to_xml(config))
  request_info(link, GetHostedZoneParser.new(:logger => @logger))
end
create_resource_record_sets(hosted_zone_aws_id, resource_record_sets, comment = '') click to toggle source

Create DNS records.

resource_record_sets = [{ :name => 'm3.mysite.patch-island.com',
                          :type => 'NS',
                          :ttl => 600,
                          :resource_records => 'xxx.mysite.com' },
                        { :name => 'm2.mysite.patch-island.com',
                          :type => 'A',
                          :ttl => 600,
                          :resource_records => ['10.0.0.1'] }]
r53.create_resource_record_sets("/hostedzone/Z1K6NCF0EB26FB", resource_record_sets, 'KD: Comment#1') #=>
  {:status=>"PENDING",
   :submitted_at=>"2011-01-18T20:21:56.828Z",
   :aws_id=>"/change/C394PNLM1B2P08"}

PS: docs.amazonwebservices.com/Route53/latest/APIReference/API_ChangeResourceRecordSets.html

# File lib/route_53/right_route_53_interface.rb, line 503
def create_resource_record_sets(hosted_zone_aws_id, resource_record_sets, comment = '')
  resource_record_sets.each{|rrs| rrs[:action] = :create}
  change_resource_record_sets(hosted_zone_aws_id, resource_record_sets, comment)
end
delete_hosted_zone(hosted_zone_aws_id) click to toggle source

Delete hosted zone.

r53.delete_hosted_zone("/hostedzone/Z2P714ENJN23PN") #=>
  {:status=>"PENDING",
   :submitted_at=>"2011-01-18T15:45:45.060Z",
   :aws_id=>"/change/C1PN1SDWZKPTAC"}

PS: docs.amazonwebservices.com/Route53/latest/APIReference/API_DeleteHostedZone.html

# File lib/route_53/right_route_53_interface.rb, line 418
def delete_hosted_zone(hosted_zone_aws_id)
  link = generate_request('DELETE', expand_hosted_zone_id(hosted_zone_aws_id))
  request_info(link, GetChangeParser.new(:logger => @logger))
end
delete_resource_record_sets(hosted_zone_aws_id, resource_record_sets, comment = '') click to toggle source

Delete DNS records.

resource_record_sets = [{ :name => 'm3.mysite.patch-island.com',
                          :type => 'NS',
                          :ttl => 600,
                          :resource_records => 'xxx.mysite.com' },
                        { :name => 'm2.mysite.patch-island.com',
                          :type => 'A',
                          :ttl => 600,
                          :resource_records => ['10.0.0.1'] }]
r53.create_resource_record_sets("/hostedzone/Z1K6NCF0EB26FB", resource_record_sets, 'KD: Comment#1') #=>
  {:status=>"PENDING",
   :submitted_at=>"2011-01-18T20:21:56.828Z",
   :aws_id=>"/change/C394PNLM1B2P08"}

PS: docs.amazonwebservices.com/Route53/latest/APIReference/API_ChangeResourceRecordSets.html

# File lib/route_53/right_route_53_interface.rb, line 525
def delete_resource_record_sets(hosted_zone_aws_id, resource_record_sets, comment = '')
  resource_record_sets.each{|rrs| rrs[:action] = :delete}
  change_resource_record_sets(hosted_zone_aws_id, resource_record_sets, comment)
end
get_change(change_aws_id) click to toggle source

Get the current state of a change request.

r53.get_change("/change/C1PN1SDWZKPTAC") #=>
  {:status=>"INSYNC",
   :aws_id=>"/change/C1PN1SDWZKPTAC",
   :submitted_at=>"2011-01-18T15:45:45.060Z"}

PS: docs.amazonwebservices.com/Route53/latest/APIReference/API_GetChange.html

# File lib/route_53/right_route_53_interface.rb, line 540
def get_change(change_aws_id)
  link = generate_request('GET', expand_change_id(change_aws_id))
  request_info(link, GetChangeParser.new(:logger => @logger))
end
get_hosted_zone(hosted_zone_aws_id) click to toggle source

Get your hosted zone.

r53.get_hosted_zone("ZWEC7PPVACGQ4") #=>
  {:config=>{:comment=>"My awesome site!"},
   :aws_id=>"/hostedzone/ZWEC7PPVACGQ4",
   :caller_reference=>"1295422234-657482-hfkeo-JFKid-Ldfle-Sdrty",
   :name_servers=>
    ["ns-794.awsdns-35.net",
     "ns-459.awsdns-57.com",
     "ns-1537.awsdns-00.co.uk",
     "ns-1165.awsdns-17.org"],
   :name=>"mysite.patch-island.com."}

PS: docs.amazonwebservices.com/Route53/latest/APIReference/API_GetHostedZone.html

# File lib/route_53/right_route_53_interface.rb, line 404
def get_hosted_zone(hosted_zone_aws_id)
  link = generate_request('GET', expand_hosted_zone_id(hosted_zone_aws_id))
  request_info(link, GetHostedZoneParser.new(:logger => @logger))
end
list_hosted_zones() click to toggle source

List your hosted zones.

r53.list_hosted_zones #=>
  [{:config=>{:comment=>"KD1, description"},
    :aws_id=>"/hostedzone/Z2P714ENJN23PN",
    :caller_reference=>"1295424990-710392-gqMuw-KcY8F-LFlrB-SQhp9",
    :name=>"patch-island.com."},
   {:config=>{:comment=>"My awesome site!"},
    :aws_id=>"/hostedzone/ZWEC7PPVACGQ4",
    :caller_reference=>"1295422234-657482-hfkeo-JFKid-Ldfle-Sdrty",
    :name=>"mysite.patch-island.com."}, ...]

PS: docs.amazonwebservices.com/Route53/latest/APIReference/API_ListHostedZones.html

# File lib/route_53/right_route_53_interface.rb, line 349
def list_hosted_zones
  result = []
  incrementally_list_hosted_zones('hostedzone', ListHostedZonesParser) do |response|
    result += response[:items]
    true
  end
  result
end
list_resource_record_sets(hosted_zone_aws_id, options={}) click to toggle source

List your resource record sets. Options: :type, :name, :max_items

r53.list_resource_record_sets("/hostedzone/ZWEC7PPVACGQ4") #=>
    [{:type=>"NS",
      :ttl=>172800,
      :name=>"mysite.patch-island.com.",
      :resource_records=>
       ["ns-459.awsdns-57.com.",
        "ns-794.awsdns-35.net.",
        "ns-1165.awsdns-17.org.",
        "ns-1537.awsdns-00.co.uk."]},
     {:type=>"SOA",
      :ttl=>900,
      :name=>"mysite.patch-island.com.",
      :resource_records=>
       ["ns-794.awsdns-35.net. awsdns-hostmaster.amazon.com. 1 7200 900 1209600 86400"]},
     {:type=>"NS",
      :ttl=>600,
      :resource_records=>["xxx.mysite.com"],
      :name=>"m1.mysite.patch-island.com."}]

PS: docs.amazonwebservices.com/Route53/latest/APIReference/API_ListResourceRecordSets.html

# File lib/route_53/right_route_53_interface.rb, line 451
def list_resource_record_sets(hosted_zone_aws_id, options={})
  options = options.dup
  result = []
  incrementally_list_resource_records("#{expand_hosted_zone_id(hosted_zone_aws_id)}/rrset", ListResourceRecordSetsParser, options) do |response|
    result += response[:items]
    true
  end
  result
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.