1
votes

Problem -

custom domain in CloudFront is not working

I'm hosting a static website in AWS. There is two S3 buckets - mydomain.com and www.mydomain.com, where the later one redirects to the first one.

In Route 53, mydomain.com points to S3 bucket as A record and wwww.mydomain.com act as an A record alias to mydomain.com.

Now I wanted to use CloudFront but wanted to be used as https://cdn.mydomain.com/asset/some-image.png. So, I added mydomain.com, www.mydomain.com, cdn.mydomain.com as Alternate Domain Names (CNAME) in CloudFront. But please note that I do not have a S3 bucket named cdn.mydomain.com

Now as required, in AWS ACM, I have also added mydomain.com as domain name and the other two (www and cdn) as alternate domain names and all of these 3 domain have CNAME records in AWS Route 53.

Finally, I wanted to route traffic from Route 53 to Cloudfront but wanted to use my desired cdn.mydomain.com instead. So, I have created A and AAA alias record in Route 53.

name - cdn

alias - Yes

alias target - cloudfront generated domain

Result :

cloudfront generated domain works and it points to my website but cdn.mydomain.com does not (IP address not found). Just at this point, I have created another S3 bucket cdn.mydomain.com and redirected to mydomain.com. But this action requires an A record to be added in Route 53. But there is already an A record for the same name - cdn.mydomain.com that points to CloudFront domain, so no way to create another alias for the same name.

If its clear what my problem is, then please suggest the solution for it.

1
It would be easier to assist if you can provide your domain name. When using CloudFront, the bucket names do not need to match the site domain, and the only A record is an alias to the CloudFront distribution, so there is not an obvious problem with your configuration, as described. Since you mentioned AAAA, did you remember to enable IPv6 on the CloudFront distribution?Michael - sqlbot
@Michael-sqlbot - that's a useful information to me. thanxx man. The domain is - greenovera.com and yes I enabled IPv6 on CloudFront Web distribution. Another information I should mention : only HTTPS is enabled for Cloudfront distribution.somnathbm

1 Answers

0
votes

Well, apparently the problem was having HTTPS only policy in CloudFront -> Viewer Protocol Policy. Don't know why it matters. Changing it to Redirect HTTP to HTTPS surprisingly solves this problem.