Best way to create website redirects on AWS

Jove Zhong
6 min readSep 30, 2022

--

Part of my role as co-founder in Timeplus, a startup company to empower developers to quickly build powerful streaming analytics applications with SQL&API, is working on CloudOps.

I will write down the lessons&learned as a series of short blog posts, and here is the first one.

Long story short, we are about to launch https://beta.timeplus.cloud and want to redirect all the following URLs to this:

  1. http://beta.timeplus.cloud
  2. http://timeplus.cloud
  3. https://timeplus.cloud
  4. http://www.timeplus.cloud
  5. https://www.timeplus.cloud

Straightforward, right? I thought it would be very easy to do so in AWS. I was not wrong but there are just too many different ways.

For the first “requirement”, there is a clear answer for that. Our cloud service is based on a Load Balancer. All you need to do is to click the Add Listener button when the ALB is selected:

Then choose Redirect as the Default actions for HTTP/80:

then set HTTPS and port as 443

This will create the 2nd listener to forward http://beta.timeplus.cloud to https://beta.timeplus.cloud Or even keep the entire path and query parameters.

DONE. There is no better options. Now if our users simply type “timeplus.cloud” in their browsers, we would like to redirect them to https://beta.timeplus.cloud.

My first idea is to add a Route53 entry, to use CNAME to add the alias. But I got the following red error:

Attempt # 2

Maybe I can create another Load Balancer. I don’t need a new Target Group. Just create the Application Load Balancer (ALB) to listen on HTTPS 443, then redirect to https://beta.timeplus.cloud. I probably need to create a HTTPS certification via ACM(AWS Certification Manager) to allow me to listen on HTTPS. Then add the other listener in that ALB to also redirect HTTP to https://beta.timeplus.cloud.

This should be a working solution. But, I have to configure ALB/ACM/Route53. What’s more concerning is the cost. ALB is not free. Even there is no EC2 instance behind the ALB, I probably still need to pay $10–20 each month for the ALB itself, plus the network traffic. Here is an example for the monthly ELB cost, for one of our components.

Attempt # 3

I also considered to create a S3 bucket as static website hosting. I simply need to put a index.html in the site/bucket to redirect to the target page, e.g.

<!DOCTYPE html><html><head><meta http-equiv="refresh" content="0; url='https://beta.timeplus.cloud'" /></head><body><p>Please follow <a href="https://beta.timeplus.cloud">this link</a>.</p></body></html>

This can work for sure. But in order to support https://timeplus.cloud I need to apply certification and also use CloudFront CDN. There are some good resources for that:

There is even a open-source CloudFormation template for this https://github.com/aws-samples/amazon-cloudfront-secure-static-site#user-content-amazon-cloudfront-secure-static-website

Again, it should be a working solution too. But I feel like it’s a bit overkill.

Attempt # 4

I also considered using the new Lambda Function URL to so. Yes, it’s fairly simple to generate a HTTPS URL for the Lambda, and I can write simple code in the Lambda to set redirect HTTP code.

Then I can add a CNAME in Route53 to redirect https://timeplus.cloud to this Lambda URL, then get it redirected again.

The problem is it won’t support HTTP. Hmm..

Attempt # 5

Our current company website is built with Wix. Don’t judge me. As a startup company with millions of things to do everyday, using Wix could be a good solution in the early days. We also purchased the paid plan to support custom domain, so that accessing http://timeplus.com will be pointing to the site hosting by wix (not via redirect)

The problem is if I create a new wix site for timeplus.cloud, I need to pay at least $6 a month to support custom domain. Hmm..

Attempt #6

Before I gave up and almost ready to launch the CloudFormation template to setup S3/CDN/etc, one idea occurred to me. Our documentation site ( https://docs.timeplus.com ) is hosted on Netlify. I am still a free-tier use for it. It simply monitors our github repo, then compile and redeploy the docusaurus-based site. Everything is free. Well, free for my usage.

What I did is to add a new site by choosing the Deploy manually option

Just create a folder with the simple index.html. Drag the folder in Netlify

It took few seconds to get it setup. Then you add your domain in

It will ask you to verify you own the domain (by adding a A record in DNS/Route53). It even can create a HTTPS certification for you, for free.

That’s all. Within few minutes, with few clicks, everything is setup in my preferred way, with 0 cost.

See, I tried/explored many options:

  1. Route53 CNAME, didn’t work
  2. The other Load Balancer, could be $20/month
  3. S3 static website hosting + CloudFront CDN, too complex, overkill
  4. Lambda Function URL, won’t work for HTTP
  5. Build a site with Wix, could be $6–9/month
  6. Build a site with Netlify. Free. Easy. Awesome.

I am very impressed for Netlify. This could be the best solution I can find to add a redirect or even a new website with minimal effort and 0 cost. I don’t blame AWS, since the S3+CloudFront could be the most mature solution they can offer. I don’t blame wix to charge $6/month, for something Netflify can offer for free. Wix is a good tool to help others to build sites. But not for such redirect use cases.

Maybe you get better idea to do so. Let me know in the comments.

Sorry, this blog is longer than I thought. But comparing to other product blogs I wrote for Timeplus, it’s much easier to write. Only took me roughly 20mins after a dinner.

I may write a few more such blogs. Also invite you to check out timeplus.com to learn more about our cool product. You may try timeplus.cloud too :)

Until next time. Peace!

--

--

Jove Zhong
Jove Zhong

Written by Jove Zhong

Co-founder & Head of Product | Timeplus

No responses yet