link a Google Domain to Amazon ec2 server

Dsel picture Dsel · Sep 8, 2015 · Viewed 19.8k times · Source

I am using an Amazon EC2 instance to serve a node.js app. I recently purchased a domain name through Google Domains and I want to use that domain name to access my node.js app.

The Google Domains console allows you to forward your domain traffic to another website. I set it to forward traffic to the public IP address of my EC2 instance. I can access my app just fine now, but when I type www.myDomainName.com into a web browser, the URL bar immediately changes and displays the digits of my EC2 IP address.

I would like the URL bar to display the name of my domain instead.

Note:
I have read a few SO questions related to this and can't figure it out. Some of them are a bit over my head. Many of them say to use an Amazon Elastic IP, but I don't understand why this is necessary if the public IP of my EC2 instance seems to work just fine. If the solution here is to use Amazon Elastic IP, I would really appreciate an explanation as to why that is necessary,

Answer

ZaxLofful picture ZaxLofful · Sep 8, 2015

It sounds like you are using Google Domains to redirect to another site once the request has hit the Google servers. This is fine and dandy if you have another domain you are wanting to redirect to.

If you want it to stay under your domain name, but point to another location you need to actually change the DNS entries for your domain.

Go to Google Domain services and change your master(*) (A) record, as well as your WWW (A) record, to point at your public IP address. That way when a DNS request is sent for your domain it will just ask Amazons' servers what to do instead of using a redirect from Google.

Exact Steps:

  1. From the Google Domain Website, click the Middle Tab (enter image description here) to open DNS settings
  2. Fill out the form near the bottom of the page titled, Custom Resource Record
    • Name: In this scenario we want to use "@" or "www"
      • @ is the root record (or anything not specifically set)[all]
      • www is the record for when people type www.example.com
    • Type: There are two types; A refers to IPv4 address and AAAA refers to IPv6 address
      • You can set both of them separately, generally you want to use the A [IPv4]
    • TTL: Time to live, recommend leaving 1hr (this is an advanced attribute)
    • Data: The actual IP address you are wanting to point to (your website)
      • Example: 8.8.8.8 [Google Nameserver]
  3. Now that are the blanks are filled out, press the "Add" button
  4. Wait for the records to be updated publicly
    • This will take approx. 1hr (as long as you kept TTL at 1hr)
      • This step can take longer depends on Google's servers
    • Check your website www.example.com to confirm it has updated