Map multiple subdomains to same S3-bucket
Asked Answered
D

2

14

Is there some way to map multiple (thousands) of subdomains to one s3-bucket? If so is it also possible to map it to a specific path in the bucket for each subdomain?

I want test1.example.com to map to mybucket/test1 and test2.example.com to map to mybucket/test2.

I know the last part isn't possible with normal dns-records but maybe there is some nifty Route 53 feature?

Delgadillo answered 25/5, 2011 at 21:10 Comment(0)
F
17

It's not possible with S3 directly. You can only use 1 subdomain with an S3 bucket.

However you can map multiple subdomains to a Cloudfront distribution.

Update (thanks to @SimonHutchison's comment below)

You can now map up to 100 alternate domains to a Cloudfront distribution - see http://docs.aws.amazon.com/general/latest/gr/aws_service_limits.html#limits_cloudfront

You can also use a wildcard to map any subdomain to your distribution:

Using the * Wildcard in Alternate Domain Names

When you add alternate domain names, you can use the * wildcard at the beginning of a domain name instead of specifying subdomains individually. For example, with an alternate domain name of *.example.com, you can use any domain name that ends with example.com in your object URLs, such as www.example.com, product-name.example.com, and marketing.product-name.example.com. The name of an object is the same regardless of the domain name, for example:

www.example.com/images/image.jpg

product-name.example.com/images/image.jpg

marketing.product-name.example.com/images/image.jpg

Fermium answered 26/5, 2011 at 15:44 Comment(4)
@Delgadillo - instructions are in my link to the Cloudfront docs. I've added an extract in my answer.Fermium
Can you have an Amazon S3 bucket accessed by "img.domain1.com" and "img.domain2.com" ? How would that increment the cost?Curia
@vtortola, the answer is yes. It's done Amazon CloudFront. Which is what this answer is describing.Imaginable
@GeoffAppleford I know this is super old, but people are clearly hitting this on google, if you have a second can you pls update answer? You can now add 100 CNAME records directly in the AWS cloudfront distribution. No need to go to Route53 at all.Bengurion
F
5

Starting from October 2012 Amazon introduced a function to handle redirects (HTTP 301) for S3 buckets. You can read the release notes here and refer to this link for configuration via Console / API.

From AWS S3 docs :

  • Redirects all requests If your root domain is example.com and you want to serve requests for both http://example.com and http://www.example.com, you can create two buckets named example.com and www.example.com, maintain website content in only one bucket, say, example.com, and configure the other bucket to redirect all requests to the example.com bucket.

  • Advanced conditional redirects You can conditionally route requests according to specific object key names or prefixes in the request, or according to the response code. For example, suppose that you delete or rename an object in your bucket. You can add a routing rule that redirects the request to another object. Suppose that you want to make a folder unavailable. You can add a routing rule to redirect the request to another page, which explains why the folder is no longer available. You can also add a routing rule to handle an error condition by routing requests that return the error to another domain, where the error will be processed.

Fibro answered 14/6, 2014 at 10:19 Comment(2)
Thank you! This is absolutely correct and should be updated as the correct answer given the changes to S3 buckets since the question was asked. Obviously the CloudFront solution will work, but this is perfect if you don't want to use a CDN.Cumae
this would work, but change the actual URL. so you still cannot have two different domains pointing to the same bucket content, if you want the user to see two different domainWhacky

© 2022 - 2024 — McMap. All rights reserved.