Creating a Domain and DNS for an AWS EC2 Instance
Super easy! That's how I would describe creating a domain and setting up DNS for your Amazon Web Services EC2 server. I wanted to create a new domain for my app, and then create a subdomain-like name for my current server to function as a beta test server. For example, it means I had an existing EC2 server operating at 10.10.10.10, and I wanted to create a domain for myapp.com, and I wanted my server at 10.10.10.10 to function like a subdomain and respond to requests for beta.myapp.com or www.betamyapp.com.
This process assumes several things. For one, that you already have an EC2 instance running. Setting up a free tier EC2 is amazingly simple. For this, I performed the following for a free-tier EC2 server running a Node app. Secondly, this assumes that you want to route directly to your EC2 server, rather than, for say, some other AWS service. And last, this assumes usage of Amazon's Route 53 service for handling DNS.
This does not try to provide comprehensive detail, for that, see the excellent documentation for Amazon Route 53.
First, navigate to the Domains dashboard: from the AWS Console, under Networking, click on Route 53 to bring up the Route 53 dashboard. Then, on the left hand menu click on Registered Domains. Click the Register Domain button. Choose a domain name and complete the purchase process. This will initiate the process, and you will have to confirm via email. This process will register your domain and automatically set up the needed hosted zones. In this case, let's assume I've registered myapp.com.
Second, review your Route 53 hosted zones. After registering your domains, within a few minutes you will receive confirmation that your hosted zones are ready. Navigate back to the Route 53 dashboard and click on Hosted Zones. Click on the name of one your hosted zones (i.e. myapp.com) and you should see the hosted zone details with the list of 4 name servers. To see the records for that zone, click on the Go to Record Sets button.
At this point, you have an EC2 instance server and a domain, myapp.com. But what we want is to route beta.myapp.com to our EC2 instance.
Third, now create a record to route requests for beta.myapp.com to your server. From the list of record sets for your hosted zone, e.g. for myapp.com, click on the Create Record Set button. This will bring up a box/form for creating a record. Enter a name for the record. You should see a Name box that provides a prefix to your hosted zone name, in this case, myapp.com. To create a record for myapp.com simply leave the Name box empty. However, in this case, we want to route traffic to our server at beta.myapp.com. So for Name, enter 'beta' and this will create a record name of beta.myapp.com. For Type, select 'A - IPv4 address' to create an A record. For Alias click No (you can't alias an EC2 instance). Leave the default TTL time of 300. For Value, enter your public IP for your server. For Routing Policy leave the default dropdown selection of 'Simple'. Now click Create!
Now you should see the new record in the list. Do the same thing and create a record for the name www.beta.myapp.com. It would be just as easy to create a record for myapp.com and www.myapp.com, but that's not what I wanted in this case. In just minutes, the created records will propagate and you should be able to ping or resolve beta.myapp.com in your web browser.