Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get hosted zone for cloudfront distribution

I'm trying to use ansible to provision Route53 failover (although the fact I'm using ansible isn't particularly relevant).

I have this task that works:

- name: Route 53 Failover | Add ALIAS   route53:   command: create   zone: "{{ top_level_domain }}"   record: "{{ cname_record_domain }}"   type: A   alias: true   alias_hosted_zone_id: "Z2FDTNDATAQYW2"   value: "{{ cname_target_domain }}"   wait: yes   failover: SECONDARY   identifier: "{{ cname_record_identifier }}"   overwrite: true 

The hard coded alias_hosted_zone_id is the hosted zone of my cloudfront distribution. The only way to find this (that I'm aware of) is to choose the cloudfront distribution as an alias in the "Add record set" dialog of the Route53 console. It then states the hosted zone in the dialog.

What I would like to do is replace the hard coded string with a variable that is populated from an aws cli command or ansible task. Is this possible?

like image 554
Joaquim d'Souza Avatar asked Sep 23 '16 16:09

Joaquim d'Souza


People also ask

Can Route53 point to CloudFront?

If you want to use your own domain name, use Amazon Route 53 to create an alias record that points to your CloudFront distribution.

Can you use CloudFront without Route53?

Yes, it is possible to use a Cloudfront distribution using a registrar other than AWS without a Route53 public hosted zone. You don't need Cloudflare to do it. You can create an Alias record with the subdomain and target in your registrar's control panel. The target would be something like dabcxyz.cloudfront.net.

Where is my AWS hosted zone ID?

You can use the Amazon Route 53 console to list all of the hosted zones that you created with the current AWS account. For information about how to list hosted zones using the Route 53 API, see ListHostedZones in the Amazon Route 53 API Reference.

Is CloudFront distribution region specific?

CloudFront delivers your content through a worldwide network of data centers called edge locations. The regional edge caches are located between your origin web server and the global edge locations that serve content directly to your viewers.


1 Answers

For CloudFront distributions, the value is always Z2FDTNDATAQYW2.

An actual citation from the Route 53 documentation itself proved more elusive than I expected -- there are (as of this writing) some search engine false-hits for this string (presumably there's some refactoring of the docs going on), but see, for example http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-route53-aliastarget.html.

like image 185
Michael - sqlbot Avatar answered Oct 03 '22 01:10

Michael - sqlbot