0

I have the following setup:

  • A documentation website hosted in an S3 bucket
  • A CloudFront distribution using that bucket as its origin, accepting HTTP or HTTPS traffic
  • 3 custom domain names registered through Route 53; let's call them example.com, .net, and .org.
  • An ACM certificate for those 3 domains so HTTPS will work
  • The example.com Hosted Zone has an ALIAS record pointing to the CloudFront distribution, so http://docs.example.com or https://docs.example.com will show the website.

Now, I want to put the following redirect rules in place. Basically, everything should redirect to docs.example.com, using whatever protocol the user originally requested with.

  1. http://docs.example.net > http://docs.example.com
  2. https://docs.example.net > https://docs.example.com
  3. http://docs.example.org > http://docs.example.com
  4. https://docs.example.org > https://docs.example.com

This is where I'm having trouble. If I point the .net and .org subdomains at the CloudFront distribution with ALIAS records, then the URL will still show that subdomain, rather than .com. If I create S3 buckets named after the .net and .org subdomains with redirect rules to the .com, and add ALIAS records to those buckets, then everything works great for HTTP, but HTTPS fails b/c the ACM certificate only works for CloudFront, not S3. And if I try to just add CNAME records to the .net and .org subdomains that point to .com then HTTPS still fails, and also HTTP redirects to HTTPS for some reason.

According to this SO post, it looks like my only option is to create two additional CloudFront distributions, one for .net and one for .org. But that just sounds so over-engineered to me, and will really bloat the CloudFormation template that I'm using to do all of this.

Can anyone recommend a simpler solution?

Rabadash8820
  • 2,328
  • 3
  • 27
  • 49

1 Answers1

0

There is no direct approach in CF to redirect across domains (Even though .com .org and .net linked to same distribution). The simplest approach I could recommend is to use AWS Edge Lambda in Cloudfront to redirect accordingly.

Ashan
  • 18,898
  • 4
  • 47
  • 67