user3770447
user3770447

Reputation: 105

How can I serve multiple sub-domains using a single Elastic IP Address in AWS using Route 53?

I have a single Elastic IP address on AWS and I want to use that IP address to route traffic to multiple distinct EC2 instances based on the sub-domain. Basically, in the same manner as virtual hosts in an Apache httpd server. For example:

All traffic for each of the domains would go to xxx.xxx.xxx.xxx and then based on the sub-domain name Route 53 would send traffic to the correct instance.

I've been through the documentation for Route 53 and I can't see how this is done. I also looked at Amazon ELB but was unsure if that would work.

Does anyone know how to set this up just using the AWS tools (Route 53 and/or ELB)? I'd rather not have to script it or use a reverse proxy if I can avoid it.

Any ideas or help would be great. Thanks in advance.

Upvotes: 4

Views: 3146

Answers (2)

E.J. Brennan
E.J. Brennan

Reputation: 46879

You don't need an elastic ip for each server. Each server already comes with an IP, so you can use that (if you actually want to address servers by ip address) - but what you likely should be doing is setting up a cname on your domain for each server, and then addressing the server's by the dns name, not by the ip address.

i.e.:

server1.example.com
server2.example.com
server3.example.com 

etc

You don't need to use any EIP's.

Maybe you could explain better why you think all the traffic needs to go thru a single IP address?

I can't say for sure why AWS limits you to just 5 EIPs, but I am pretty sure its because if you find out you need hundreds of EIP's then you are probably doing it wrong - and forcing you to request more than 5 gives them the ability to open up a discussion with you and help you do it a better way.

Upvotes: 4

Matt Houser
Matt Houser

Reputation: 36113

You'll need 1 Elastic IP address for each distinct EC2 instance that you want to redirect traffic to.

  1. Create your CNAME or ALIAS record for example.com and point it to your ELB.
  2. For each distinct EC2 instance that you need a sub-domain for, do the following:
    1. Allocate an Elastic IP address.
    2. Assign that Elastic IP address to the EC2 instance.
    3. Create an A record in Route 53 pointing subdomain.example.com to that Elastic IP address.

Note: Since your EC2 instances need to be accessed directly, they will need to reside inside a public subnet.

Upvotes: 0

Related Questions