Amazon ELB is an auto scalable load balancer that sits in front of EC2 instances and distributes traffic between them. Client communicates with ELB not with EC2 instances directly.
When you create a ELB you get a domain name provided by Amazon AWS to make requests to the ELB. This domain name resolves to different IP address over time. This is done so that Round Robin DNS can be implemented as traffic to the load balancer increases therefore auto scaling takes place.
Pointing Root Domain or Subdomain to ELB by changing A or AAAA Settings
Changing A or AAAA records means changing the IP address associated with the domain name. As ELB doesn’t have a static IP address therefore we cannot use A or AAAA records in our domain registrar’s control panel to point domain to the ELB.
Pointing Root Domain or Subdomain to ELB by changing Nameserver Settings
Changing nameserver gives AWS complete control over the domain. Nameserver is changed at root domain level.
You can change the nameservers of your domain at your domain registrar’s control panel. To get the nameserver values from AWS, create a Route 53 hosted zone with the root domain name and you will get the nameserver values under NS record type.
Now create a A record and point it to the ELB as alias not with direct IP address because IP address of the ELB is not static. Now Route 53 will keep updating the IP address of the A record to match the IP address of the ELB.
Here is an screenshot which shows an example of Route 53:
Note: Changing nameserver redirects email traffic to AWS which is not what you may want if you are using an email address with the associated domain. You can create a MX record set to redirect email traffic to somewhere else.
Pointing Root Domain or Subdomain to ELB by changing CNAME Settings
A root domain cannot have a CNAME associated with it. Only subdomains can have CNAME associated with it. CNAME is used alternative to A or AAAA records. A CNAME is an another domain. When we set a CNAME for a subdomain then the IP address of the subdomain is made same as the IP address of the CNAME.
To point a subdomain to ELB you can simply use the domain of the ELB as CNAME.
Note: Changing CNAME doesn’t affect email traffic.
Pointing Root Domain to ELB without changing Nameserver settings
We saw that a root domain can be pointed to an ELB by changing nameserver settings only. But if you don’t want to change the nameserver settings and still want to point the root domain to ELB then there is a workaround.
For example: if you have a domain named example.com and if you want to point it to an ELB then you can create a subdomain called as www.example.com. As subdomain can point to ELB via CNAME so point the www.example.com to the ELB. Now using domain forwarding forward example.com tarffic to www.example.com. So now you have indirectly pointed the root domain to the ELB.
It is completely okay to use www subdomain as many major sites use www subdomain and redirect traffic for root domain to www subdomain.
This way you don’t have to worry about MX settings also as they are not affected.