I'm struggling with my S3 and CloudFront setup for my website, and I'm not sure where I'm going wrong. I have two S3 buckets: one for my origin domain (example.com) that contains all my static files, and another for the www version (www.example.com) that redirects to the origin bucket. I also set up two CloudFront distributions — one for each bucket, each with its own TLS certificate. My Route53 configuration has example.com pointing to the CloudFront distribution for the non-www bucket, and www.example.com pointing to the distribution for the www bucket. The issue is when I navigate to www.example.com, the URL redirects incorrectly to the CloudFront URL of the non-www distribution, which adds an extra "https//" in the URL. I'm hoping someone can guide me on how to fix this. Thanks!
3 Answers
You don't actually need to have two buckets for this setup. It's often simpler to just use one bucket for the www version and handle the DNS redirection there. You can set up your DNS provider to redirect the root domain to the www version, and then CloudFront will handle the HTTPS for you. This will streamline your setup significantly!
If you're still having trouble, I recommend checking out some tutorials or posts on the topic. There's a really helpful guide linked here: https://www.reddit.com/r/devops/s/B97WP7s6th. It might give you more clarity.
Thanks for the resource! I'll check it out for further guidance.
You can simplify your S3 and CloudFront setup by creating just one S3 bucket for your content. Make that bucket private and then create a CloudFront distribution using that bucket as the origin. For DNS, make sure to create an A record that leaves the name blank for the root domain and another for www, both pointing to the same CloudFront distribution. Also, remember to create an ACM certificate that includes both domain.com and *.domain.com, so it covers both versions adequately.
Exactly! Also, make sure your SSL certificate includes both domain variations for a smooth experience.
Great advice! Just a heads-up: users will see the domain they entered in the browser. If you want everyone to end up on the same domain (like always going to www), you'll need to set up a redirect in CloudFront. It's straightforward!
Thanks for the tip! I figured the two bucket approach was overcomplicating things. I'll give the single bucket method a try.