Redirecting to the IP of an amazon EC2 instance

As you know amazon EC2 instances get an address like:

ec2-72-44-40-153.z-2.compute-1.amazonaws.com

If I have the domain example.com, is there any way that I can make bob.example.com or preferably example.com/bob redirect to the IP of

ec2-72-44-40-153.z-2.compute-1.amazonaws.com

??

Thanks!!


If you just want to redirect a domain, you can create a CNAME record in DNS:

bob.example.com IN CNAME ec2-72-44-40-153.z-2.compute-1.amazonaws.com

Which will redirect everyone trying to connect to bob.example.com to your EC3 site.

If you want example.com/bob to redirect, you will need to configure some URL rewrite rules on the webserver running on example.com.


Amazon has provided a solution that is perfect for your requirements, and more flexible than a CNAME record. You can request a so-called Elastic IP address from EC2.

This IP address is static, so you can create an A record in your DNS that points to it, but it points to an EC2 instance of your choosing. A regular A record like the following would be fine:

bob.example.com    A    123.123.123.123

If your server goes down and you boot another instance (which gets a different hostname), simply reallocate the Elastic IP to the new instance. In a minute or two, the new instance is available behind the IP. This means there will be far less delay than you would experience from a DNS change.

Elastic IPs are free, as long as they are in use. You get charged a small hourly amount when you're not using the IP. This is done to discourage bad usage of limited resources.

You can request and assign the Elastic IP's via the API tools, or a GUI such as ElasticFox. Reading Amazon's howto will make things clearer.