0

I am hosting a static website on AWS using Amazon S3 + CloudFront + HTTPS.

I need to ensure that the website is opened by only one of the CNAMEs and not the other (non-www). The S3 domain must also be forwarded to the main WWW domain.

How can this be done?

2 Answers 2

0

You need to use S3 to redirect the requests.

  1. You will firstly need to create two buckets with the names: www.example.com and example.com and provide appropriate bucket policies
  2. You will then need to redirect all the traffic from example.com S3 bucket to www.example.com by going into static website hosting settings. Check out the below settings

enter image description here

  1. Now, you have to setup the CNAME in Route53 such that example.com will translate to www.example.com
  2. Create a distribution for www.example.com and use the alternative CNAME as www.example.com
0

If I understand you correctly, you can add a CNAME to a CloudFront Distribution from within the CloudFront console. You can also add a CNAME to a CloudFront distribution in Route53 by selecting to add a CNAME, click the Alias=yes radio button and select the relevant CloudFront resource.

See image below for where this is done in Route 53:

enter image description here

3
  • CNAME will not forward the request on cloudfront
    – Karan Shah
    Feb 1, 2017 at 2:19
  • @Karan Shah - I'm pretty sure it does. See the image in my answer for where this is done. Feb 1, 2017 at 2:31
  • I did mention using CNAME as a part of my answer.
    – Karan Shah
    Feb 1, 2017 at 2:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.