How can I obtain the Hosted Zone ID of an AWS ELB in Ruby?

I'm writing some Ruby code to automatically update Route53 DNS zones (domains) using the Zone apex virtual A record feature. However, to setup such records requires the Elastic Load-balancer Hosted Zone ID in addition to the FQDN.

Does anyone know the best way to do that? (i.e. any gems etc that can do it?) I'm currently using the appoxy aws gem in combination with pcorliss's route53 gem.



In the modern AWS Ruby SDK's ELB module, I came up with this solution (partially pseudo-code):

credentials_data = # something
config = AWS.config(credentials_data)

elb_name = ''
elb_client = config.elb_client
response = elb_client.describe_load_balancers()
elbs = response[:load_balancer_descriptions]
the_elb = {|elb| elb[:dns_name] == elb_name}.first
the_hosted_id = the_elb[:canonical_hosted_zone_name_id]

Then, when doing your Route53 stuff, later, you can include this data as:

# ...
:alias_target => {
  :dns_name => elb_name,
  :hosted_zone_id => the_hosted_id,
  :evaluate_target_health => true, # or false, if you wish
# ...

I admit, I do wish there was a nice "ruby-ish" (more idiomatic) front-end to all of this (or perhaps there is, and I just need to go find it), but the above worked for me using the stock aws-sdk gem. Hopefully that's helpful for someone at some point.

Need Your Help

Unable to upload an APK file to hockey app via their API

android curl continuous-integration hockeyapp teamcity-9.0

I am unable to upload an android apk to hockeyapp through the API provided by them.When i use

Change some fields in a file

ruby string file

I need to analyses a file and change some fields.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.