´╗┐How To Link A Domain Name To An Amazon EC2 Instance

The official Amazon guide for linking a domain name to an Amazon instance is pretty good, but it is a bit vague on a couple of key steps, which is what I explain below. 

Fix Your IP Address

When you start up an Amazon EC2 instance, you get a public IP address. If you put that address in a web browser then you should see your website. However, by default that IP address is not fixed, and it's reset every time you turn your instance on or off.

That’s no good, we need a fixed IP. That is easy to do with Amazon’s Elastic IP.

  1. Login to Amazon EC2.
  2. Click on your instance.
  3. Look at the bottom under Description and then Elastic IP. If there is nothing there then you do not have a fixed IP address.
  4. On the left-hand navigation pane, click “Elastic IPs”.
  5. On the Elastic IP page, click on the button “Allocate new address”.
  6. Click “Allocate”.
  7. Your new Elastic IP should now show up.
  8. Right click on the new Elastic IP address, click “Associate address”
  9. Select your instance from the drop-down list, then click “Associate”
  10. Sanity check – Navigate back to your EC2 instance, click on it, the Elastic IP address should now show up in the “Description” page.

Okay great, so now we have an IP address that sticks around if we turn the instance off and on again. That’s good. 

If you navigate to your new Elastic IP address in a browser then you should see your website. 

NOTE – If you do not see your website at the IP address then you might need to update your project settings to the new IP address. This will depend on what kind of website or application you have. For example if you are using Django and nginx, then you may need to update the ALLOWED_HOSTS setting in Django and the nginx conf file. 

Link To Your Domain name

Okay, so now we have a fixed IP address, that's good. But our address is just a bunch of numbers, that's bad. So let’s link it to a domain name. 

  1. Follow the offical Amazon guide to setup Route 53. This is pretty good, but it misses out a crucial step that you need to do with your domain registrar.
  2. Once Route 53 is setup, you need to tell your domain name registrar. You do this by updating your nameservers. How this works depends on who you registered your domain with. Generally, if you login to your account with your domain name registrar, there should be an option to change the nameservers on your domain. Do that and add the 4 nameservers that are listed in the Hosted Zone in the Amazon Route 53 management Console.

Route 53 Nameservers

The nameservers are listed as in the picture above. I've blacked out the actual values in this image for security reasons.

Now you just need to wait for the changes to propogate. Once they have propogated, if you navigate to your domain name address then you should see your website. It will probably only take a few minutes for the changes to propogate, but it might take a few hours, so wait a while if it’s not working. The reason it might take a while is because the DNS records are cached in lots of different places, and it can take a while to propagate through. 

Now You’re Live

That’s it. Your website should be live now. 

This is one of those things that can seem very daunting at first, but once you’ve done it a few times you see that it’s actually not that difficult.

Read next