Pergunta

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.

Thanks.

Foi útil?

Solução

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 = 'your.elb.dns.name.elb.amazonaws.com.'
elb_client = config.elb_client
response = elb_client.describe_load_balancers()
elbs = response[:load_balancer_descriptions]
the_elb = elbs.select {|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.

Outras dicas

The Aws gem Aws::Elb code is using AWS ELB API version 2009-05-15. There have been several API version updates by Amazon since then - the latest currently being 2011-11-15.

The format of the DescribeLoadBalaners response was changed between version 2009-05-15 and version 2009-11-25, which breaks the current Aws::Elb code (Listeners was changed to ListenerDescriptions). Also, the hosted zone elements in the response weren't added until version 2011-04-05.

It is possible to get the hosted zone information by hacking the Aws::Elb source to use the latest API and extract the relevant data.

Now we just need to get the Aws maintainers to update the official gem.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top