Last active
August 29, 2015 14:08
-
-
Save sorah/9403b7ee2e4c2440b5a4 to your computer and use it in GitHub Desktop.
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 'net/https' | |
require 'nokogiri' | |
require 'uri' | |
require 'time' | |
require 'base64' | |
require 'openssl' | |
abort "Usage #{$0} zoneid" unless ARGV[0] | |
token = ENV['AWS_ACCESS_KEY_ID'] | |
secret = ENV['AWS_SECRET_ACCESS_KEY'] | |
zoneid = ARGV[0] | |
date = Time.now.httpdate | |
url = URI("https://route53.amazonaws.com/2013-04-01/hostedzone/#{zoneid}") | |
req = Net::HTTP::Get.new(url.path) | |
req["Date"] = date | |
sign = Base64.encode64( | |
OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha256'), | |
secret, date) | |
).strip | |
req['X-Amzn-Authorization'] =[ | |
"AWS3-HTTPS AWSAccessKeyId=#{token}", | |
"Algorithm=HmacSHA256", | |
"Signature=#{sign}" | |
].join(',') | |
http = Net::HTTP.new(url.host, url.port) | |
http.use_ssl = true | |
http.start do | |
res = http.request(req) | |
puts Nokogiri::XML(res.body).to_s | |
end |
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
<?xml version="1.0"?> | |
<GetHostedZoneResponse xmlns="https://route53.amazonaws.com/doc/2013-04-01/"> | |
<HostedZone> | |
<Id>/hostedzone/...</Id> | |
<Name>aws.her.</Name> | |
<CallerReference>...</CallerReference> | |
<Config> | |
<PrivateZone>true</PrivateZone> | |
</Config> | |
<ResourceRecordSetCount>5</ResourceRecordSetCount> | |
</HostedZone> | |
<!-- VPCs should be in <HostedZone> ? --> | |
<VPCs> | |
<VPC> | |
<VPCRegion>ap-northeast-1</VPCRegion> | |
<VPCId>vpc-XXXXXXX</VPCId> | |
</VPC> | |
</VPCs> | |
</GetHostedZoneResponse> |
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
# gem i nokogiri | |
require 'net/https' | |
require 'nokogiri' | |
require 'uri' | |
require 'time' | |
require 'base64' | |
require 'openssl' | |
token = ENV['AWS_ACCESS_KEY_ID'] | |
secret = ENV['AWS_SECRET_ACCESS_KEY'] | |
date = Time.now.httpdate | |
url = URI('https://route53.amazonaws.com/2013-04-01/hostedzone') | |
req = Net::HTTP::Get.new(url.path) | |
req["Date"] = date | |
sign = Base64.encode64( | |
OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha256'), | |
secret, date) | |
).strip | |
req['X-Amzn-Authorization'] =[ | |
"AWS3-HTTPS AWSAccessKeyId=#{token}", | |
"Algorithm=HmacSHA256", | |
"Signature=#{sign}" | |
].join(',') | |
http = Net::HTTP.new(url.host, url.port) | |
http.use_ssl = true | |
http.start do | |
res = http.request(req) | |
puts Nokogiri::XML(res.body).to_s | |
end |
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
<?xml version="1.0"?> | |
<ListHostedZonesResponse xmlns="https://route53.amazonaws.com/doc/2013-04-01/"> | |
<HostedZones> | |
<HostedZone> | |
<Id>/hostedzone/...</Id> | |
<Name>her.tokyo.</Name> | |
<CallerReference>...</CallerReference> | |
<Config> | |
<PrivateZone>false</PrivateZone> | |
</Config> | |
<ResourceRecordSetCount>8</ResourceRecordSetCount> | |
</HostedZone> | |
<HostedZone> | |
<!-- No VPCs --> | |
<Id>/hostedzone/...</Id> | |
<Name>aws.her.</Name> | |
<CallerReference>...</CallerReference> | |
<Config> | |
<PrivateZone>true</PrivateZone> | |
</Config> | |
<ResourceRecordSetCount>5</ResourceRecordSetCount> | |
</HostedZone> | |
</HostedZones> | |
<IsTruncated>false</IsTruncated> | |
<MaxItems>100</MaxItems> | |
</ListHostedZonesResponse> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment