Last active
August 29, 2015 14:03
-
-
Save tiagolnobre/d3f84f563911b6796216 to your computer and use it in GitHub Desktop.
change route53 ruby aws sdk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'aws-sdk-core' | |
zid = nil | |
r53 = Aws::Route53.new | |
r53.list_hosted_zones[:hosted_zones].each do |zone| | |
id = zone[:id].match(/\/hostedzone\/(.*)/)[1] | |
puts zone[:name] + ':' + id | |
if (zone[:name] == "testing.com.") then zid = id end | |
end | |
# zone | |
zoneinfo = r53.get_hosted_zone({:id => zid}) | |
# records for zone | |
records = r53.list_resource_record_sets({:hosted_zone_id => zid}) | |
# get resource by dns name | |
resp = r53.list_resource_record_sets({:hosted_zone_id => zid, :start_record_name => "dns.testing.com", :max_items => 1}) | |
# create or change dns | |
resp = r53.change_resource_record_sets({ | |
:hosted_zone_id => zoneinfo, | |
:change_batch => { | |
:comment => "create subdomain", | |
:changes => [{ | |
:action => "UPSERT", | |
:resource_record_set => { | |
:name => "dns.testing.com", | |
:type => "A", | |
:ttl => 300, | |
:resource_records => [{ | |
:value => "172.192.1.26" | |
}] | |
} | |
}] | |
}}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment