AWS Route 53 redirecting to an external https domain.

Joshua Toth
3 min readJul 1, 2019

--

tldr: inside an s3 bucket with site hosting add a redirect.html file, a CloudFront distribution that loads the file and a route53 record set that adds an ‘Alias’ for the CloudFront distribution. Solution and code below.

My Journey to this solution

Recently I re-launched a new design of my personal site, this also involved moving the domain from joshuatoth.com to jjt.dev. Having registered joshuatoth.com on AWS and jjt.dev on google domains.

Before the launch I had my jjt.dev redirecting to google domains via the ‘redirect’ domain control. Super simple

But when I had to do the forwarding in the other direction AWS was not as easy. There are a couple of recommended forwarding methods that AWS has noted down, however these didn’t work for my use case.

The first method that didn’t work for me was the s3 bucket redirecting. The first issue I had with this was: My s3 bucket wasn’t showing up in the ‘Alias Target’ list. This is because your bucket name has to be exactly the same as the name of the Record Set. i.e. my record set was joshuatoth.com, my bucket name needed to be joshuatoth.com.

Setting an alias target for an existing s3 bucket

‘But what if that bucket name is already taken?’ you say. Well you’re outta luck on this method.

Eventually I got the alias set up for the root host, but what I was presented with was infinite loading of https://joshuatoth.com.

After some digging I came to the conclusion that because my jjt.dev site is hosted on Github Pages and it’s enforcing HTTPS, which the s3 redirect doesn’t like so much. Another downfall of this method would have been the second bucket for www.joshuatoth.com and a second Route 53 record set.

The next step to this would be to setting up a CloudFront configuration that acts as the redirect for you. This however wasn’t ideal as AWS needed to have an ssl cert for https://jjt.dev and that was located on another service entirely.

Solution

My end solution was to add a redirect.html file within my old site hosting bucket with a small redirect page. Then I pointed the CloudFront distribution I already had to the new page instead of index (this was using the original SSL certificate I had for joshuatoth.com). The final step was to have two aliases on my domain pointing to the CloudFront distribution.

redirect.html:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="refresh" content="0; url=https://jjt.dev">
</head>
<body>
</body>
</html>

Bucket settings:

Using the bucket to host the single file

CloudFront distribution settings:

Note the SSL Certificate is for the original domain

Route 53 Record set:

There is also a record for www.joshuatoth.com

Honestly this was a lot more effort than it really should have been. It would be nice for some sort of redirect service to be available within AWS itself. I will probably at some point migrate my domain to Google domains, however I have email set up for this domain so there would be some downtime on my professional email which would be inconvenient at this time.

This is my solution and others may vary. Feel free to let me know if you have found another solution that works for you!

--

--