5

I have been working with AWS for over a year, setting up EC2 instances, domains, ELBs, etc.

When I want to assign a subdomain to an EC2 instance, I have to create an elastic IP (that I pay for), then assign a CNAME record to that elastic IP.

When I want to assign a subdomain to an ELB (load balancer) instance, I just create an alias resource record set to the ELB.

I've read over the docs and don't understand why AWS doesn't support aliasing to instances. Am I missing a key concept here? Wouldn't it be simpler to just alias EC2 instances and skip the whole elastic IP bit?

EDIT: To put it simply - why are my EC2 instances not on this list: enter image description here

2 Answers 2

6

The short answer is: You can create an A or CNAME record to the external IP address or the DNS name of your instance, but you don't want to do this.

The long answer: You actually can create a CNAME (or even A) record without an Elastic IP. But every time your EC2 instance is restarted and so moved to another host system the IP address (and your external hostname) of your instance will change. If you can live with this and accept the fact that during the TTL of your DNS record your instance is not reachable you can use the external IP and create an A record with your subdomain. But as DNS is not very fast in distributing changes (even with a low TTL you can't make sure every resolver handles the TTL correctly) you don't want to do such things most of the times. This is why AWS provides the Elastic IP - so your IP address which is in the DNS record never changes but the routing behind this IP address is changed by AWS if you reassign it to another instance (or you reboot your host). This routing change is only inside the AWS data centers and so it is quite fast (within a few seconds) and your instance is reachable again for all users.

Hope this helps!

4
  • So, just to ensure: it is not possible to create an alias, but it is possible to achieve pretty much the same with an A or CNAME record? Jul 30, 2015 at 12:37
  • Like I already said: if you can live with some downsides (TTL etc) you can point an A record or a CNAME to your instance.
    – Osterjour
    Jul 31, 2015 at 13:11
  • 1
    Yeah, just wanted to make sure that making alias in Route53 is technically different from using A or CNAME and AWS does not support alias here. With alias, Route53 DNS server will directly return the IP address, with CNAME client needs to recurse the query to the next server. With A record though... not sure what is the difference, if any. Please correct me if wrong. Aug 1, 2015 at 10:17
  • With an A record the IP will be directly returned. But as the IP isn't a static one (as the OP wanted to skip Elastic IPs) the IP (same as the external host name you would use in the CNAME) may change on every restart/failure of the instance.
    – Osterjour
    Aug 2, 2015 at 10:38
1

Elastic IP addresses are only paid for if they are unassigned (ie. unused). As long as your Elastic IP address is assigned to your instance, you do not pay for it.

IF AWS supported DNS aliases to the non-elastic IP addresses of instances, then whenever those public IP addresses changed, then the DNS would be out-of-date. Elastic IP addresses keep the IP address consistent.

However, I agree that I could see value in adding alias support for Elastic IP addresses though.

2
  • "whenever those public IP addresses changed, then the DNS would be out-of-date" - sure, but AWS could easily update their alias mapping to the new DNS correct?
    – grokpot
    May 28, 2014 at 13:04
  • Yes, but all the cached values from previous resolutions would be wrong until the TTL expired. May 28, 2014 at 23:12

Not the answer you're looking for? Browse other questions tagged .