Robsonsjre
Robsonsjre

Reputation: 1606

How to point a subdomain to the same S3 bucket using Route53?

I am creating a white-label website hosted on an S3 Static Website, for clothes stores that based on subdomain will fetch different data from the database. But I want all to point to the same S3 Static Website, the subdomain only purpose is to differ logo and some other information. For example:

store1.maindomain.com store2.maindomain.com

How do I do that in Route53? Below is my configuration, trying CNAME pointing to wwww.maindomain.com did not worked, keep saying '404 not found'.

enter image description here

Upvotes: 1

Views: 536

Answers (1)

Matt D
Matt D

Reputation: 3496

The storeone.atacadapp.com CNAME will resolve to one of the AWS S3 endpoints, but there is not an S3 bucket called storeone.atacadapp.com, so S3 rejects the request. The key here is the host name used in the browser is the one the S3 service tries to match, not some intermediary host name.

I think that your best bet is to use CloudFront to create a distribution that knows about all of the host names that you are using. In CloudFront register an origin for your S3 Static Website. All requests will be forwarded to that S3 Bucket, no matter which of the registered host names has been used.

Then use some code in your application to identify the host name that was used and load properties from your database for that hostname. In JavaScript use window.location.hostname

Upvotes: 2

Related Questions