Apr 4, 2012
Yesterday I observed an interesting situation. Let’s take a look at the following use-case:
Let’s assume we have a web project hosted in Amazon Cloud. In Amazon, we do have a simple cluster with 2 nodes and the load balancer at the front. Next, we have a domain foo.com and we are using dyndns to manage dns records for our domain. Our goal is to point our domain to the load balancer.
Obviously, there is no issue if the load balancer has a fixed IP. We just have to create “A” record for the domain and put it to the IP address. According to Amazon, as the set of IP addresses associated with a LoadBalancer can change over time, you should never create the “A” record with any specific IP address. If you want to use a friendly DNS name for your LoadBalancer instead of the name generated by the Elastic Load Balancing service, you should create a CNAME record for the LoadBalancer DNS name, or use Amazon Route 53 to create a hosted zone.
Since we already use DynDNS, a way to jump to Amazon Route 53 is not a solution and fortunately, I was able to find a way to put a domain and the load balancer together.
1. In the DynDNS management panel, create the A (WebHop) Record for http://www.foo.com/
2. Create the CNAME record for www.foo.com and point it to the A record of the load balancer. Btw, it was quite confusing for me, because Amazon gives the A record like an URL (httpBalancer-XXXX.us-XXX-X.elb.amazonaws.com ).
That’s it. Now, when you type in browser http://foo.com/ you will be redirected to http://www.foo.com/ and the request will reach the load balancer subject to the CNAME for www.foo.com.
P.S. I’ve read somewhere that Google doesn’t like any redirects (302), so I am not sure if the above approach is OK. Do you know a better way ?