Pablo Fernandez
Pablo Fernandez

Reputation: 287410

HTTP redirects in the AWS world, anything better than S3+CloudFront?

I'm moving my domain names from CloudFlare's DNS to AWS Route53 and in some cases I'm using CloudFlare's redirects for project that are dead so that their domains go to a page in another domain, so https://projectx.com goes to https://example.com/projectx-is-no-more.

I want to replicate this in AWS and what I found so far is this:

  1. Set up an S3 bucket with the redirect to the desired URL, https://example.com/projectx-is-no-more
  2. Set up CloudFront for the domain, projectx.com
  3. Generate the TLS cert for projectx.com and add it to CloudFront so it can serve both https and http.
  4. Set up Route53 to resolve the domain name to CloudFront.

I set it up, it's working, I'm even using CDK so I'm not doing it manually. But I'm wondering if there's a way of setting up these redirects that requires less moving pieces. It sounds like such a redirect would be a common enough problem that maybe Route53 or CloudFront would have a shortcut. Are there any?

Update: using only S3 doesn't work because S3 cannot serve https://projectx.com. S3 has no method by which it can respond to HTTPS request for arbitrary domains, there's no way of adding a TLS certificate (and keys) for another domain.

Upvotes: 1

Views: 206

Answers (2)

rzlvmp
rzlvmp

Reputation: 9364

I checked for information and see only three possible solutions:

  1. Set up CloudFront + S3 *
  2. Set up Application Load Balancer
  3. Set up API Gateway + Lambda (mock integration may be used instead of Lambda, that should reduce service cost)
  4. Use GitHub pages with custom domain

※ S3 support only HTTP traffic so we need to add CloudFront for HTTPS:

Amazon S3 does not support HTTPS access to the website. If you want to use HTTPS, you can use Amazon CloudFront to serve a static website hosted on Amazon S3.

In my opinion the ②nd way is super easy to set up but running 24/7 ALB is little bit expensive. In other way Lambda and API Gateway price depending on requests count. CloudFront seems to be cheaper than ALB too.

So the better solution is depending on how many requests you have

The ④th solution is depends on GitHub platform (wider than AWS only scope), but it is absolutely free and support custom domain and Let's Encrypt certificates out of the box. You just need to create repository with static index.html file that will do redirects

Upvotes: 1

Caldazar
Caldazar

Reputation: 3757

You can do it without including CloudFront.

What you need to do is create S3 bucket projectx.com. In Properties go to Static website hosting. Enable static website hosting and choose Redirect as a hosting type (add the redirection URL).

You will still need to set up Route53, but you will now add alias to this projectx.com bucket, instead of going to CloudFront

Upvotes: 0

Related Questions