Fixing URL-based Redirect Errors for AWS Route 53 and S3

Many of the typical DNS providers offer what we call URL-based redirects. This is something where a 301 HTTP response is applied to the DNS query and an answer of a new DNS name is sent back in order to forward you to the new URL.

This is not something that is natively available in AWS Route 53, but I’ve written about the solution here in the past where we can use S3 buckets and the website hosting and redirection option. The flow that the client will see is:

  • request URL (e.g. gcondemand.io)
  • DNS responds with record from Route 53 with an S3 alias
  • S3 redirects to the new URL using HTTP 301 response

Domains No Longer Forwarding using Route 53 and S3

The only challenge comes when you set up a domain on Route 53 and you are asked which DNS servers are the authoritative NS records to inject. New zones work automatically by injecting AWS name servers which will be dynamic within the AWS environment.

When a zone is transferred, the question will be presented if you want to keep your existing NS settings from the original registrar or if you want to specify your own NS settings which means setting up some NS records that you assume are all good. Here’s the trick: your NS records must contain the same entry as the SOA (Start of Authority) or else bad things will happen in time.

This is an example of a domain that was transferred over, given NS entries, and worked for quite a while. Suddenly, this is what will happen:

But, it worked for a while…

DNS is a magical thing (spoiler: it’s not really magic), and will work for quite a while as the internet continues to dynamically find your zone redirect on the previous name servers. At some point, you will bump into the issue where the records will age out on other servers and when downstream DNS servers go hunting for your records, the zone is pointing to differing NS records.

Fixing your Simple Redirects using Route 53 and S3

Fire up your Route 53 console, choose your hosted zone, and then select the Go To Record Sets button to edit the zone.

You can see by our entries here that we have a mismatch from the SOA and the NS records:

I’ve gotten four AWS DNS servers that I will use here:

ns-1881.awsdns-43.co.uk
ns-875.awsdns-45.net
ns-134.awsdns-16.com
ns-1457.awsdns-54.org

That will fix the first issue of the mismatched NS records and the SOA being different:

For the second part of the fix, go to the Registered Domains section in the Route 53 console, and select the Add or Edit Name Servers section under your zone.

Now, make sure to replace the four records with the matching set of four NS records you’ve used within the Hosted Zone section:

That will get you all sorted out. Don’t forget that DNS is a cached both locally and on remote DNS servers, so it may take up to 5-15 minutes for your local cache to expire and it may take up to a few hours for the remote entries to become corrected.

Hopefully that gets you all fixed up if you’ve had a similar issue!




Simple HTTP Redirects Using AWS Route 53 and S3

Let’s just say that you want to create a redirect for a root domain while using Route 53 on Amazon Web Services.  Many of the popular domain registration and web hosting providers (e.g. GoDaddy, Domain.com, etc.) have baked in settings to redirect to another URL.

In Route 53, there is no native way to do this, but luckily it’s a couple of simple steps away and you also get to learn a little about web site hosting on AWS S3 (Simple Storage Service) at the same time.

My example is for http://virtualdesignmaster.com which has been redirected to http://virtualdesignmaster.io as you can see by clicking the link.  Now, let’s learn how to do that easily with AWS Route 53 DNS service and S3.

Our assumption is that you’ve registered the domain with Route 53 or are at least hosting the DNS zone and have set the SOA (Start of Authority) record and NS (Name Server) records to AWS DNS settings.

Setting up Your S3 Buckets

The reason that I say buckets as a plural, is that we will want to have a working DNS for both the root domain virtualdesignmaster.com and also the www.virtualdesignmaster.com which is normally a CNAME entry to point to the root domain.

Open up your AWS S3 and click the Create Bucket button.  Name your S3 bucket the same as your domain name.  In my case for the example is virtualdesignmaster.com.  I’ve chose to put it in the US Standard region because it’s the closest to the majority of my traffic for the site:

01-create-bucket-base

 

After you click the create button, you need to click the Properties button on the upper right side of the page.  Expand the section which says Static Website Hosting, select the Redirect all requests to another host name radio button, and type the URL that you want to redirect to.  In my case it is www.virtualdesignmaster.io:

02-bucket-redirect-base

Save the changes and repeat the process, but this time you will name the S3 bucket as the www name for your domain.  My example uses www.virtualdesignmaster.com:

03-create-bucket-www

Open the Properties section, expand the section which says Static Website Hosting, select the Redirect all requests to another host name radio button, and type the URL that you want to redirect to:

04-bucket-redirect-www

That is your S3 configuration.  Next up is the DNS settings.

Route 53 Configuration for S3 Targets

Open up your Route 53 configuration in the AWS console.  Select the Hosted Zones area, choose the radio button for the zone we are working on and click Go to Record Sets:

route53-vdm

Click Create Record Set.  Leave the Name section empty, choose A – IPv4 address as the Type:

05-create-a-record-base

Change the Alias from the default of No to Yes:

06-alias

Click in the Alias Target field which brings up a droplist.  It may take up to 20 or more seconds to populate the list.  Under the S3 website endpoints you will see the one you’ve created.  Select that and click the Create button at the bottom:

06-route53-base

Repeat the process of adding a new record.  This time put www in the Name section.  Keep A-IPv4 address as the Type, and click the Alias Target section to select the S3 website endpoint which matches the A record name:

07-route53-www

DNS is a rather magical system, but it will take up to 15 minutes or more update.  Once some time has passed, you can confirm te redirection is in place by trying the URL in a browser.  It should redirect you to the web site that you’ve assigned in your S3 configuration.

You can confirm from the command line using cURL as well.  Type curl --head yourdomain.com which will show you the output below, and then you can also type curl yourdomain.com which will show you the redirect in the output:

08-curl-redirect

Note that this is different than a 301 or 302 redirect.  The method used by the S3 redirection is a META tag instead.  I’m also assuming that you’re aware that there is a cost for the S3 usage.

Costs of Using S3 for Web Site Hosting and Redirection

As listed on the S3 and storage pricing site, the S3 usage qualifies for a Free Tier to AWS users up to the first 20,000 HTTP GET requests per month for the first year of usage.

aws-s3-free-tier

After your Free Tier usage expires, you are charged 0.004$ per 10,000 HTTP GET requests per month in the US East region.  Pricing across regions can be different, so make sure to take that into account when you choose the location of your S3 buckets:

aws-s3-pricing-GET

Hopefully this helps, plus it’s also handy to know as part of your study towards the AWS Solutions Architect Associate exam.