Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Map multiple subdomains to same S3-bucket

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?

like image 642
Martin Avatar asked May 25 '11 21:05

Martin


People also ask

Is it better to have multiple S3 buckets or one bucket with sub folders?

The total volume of data and number of objects you can store are unlimited. Also the documentation states there is no performance difference between using a single bucket or multiple buckets so I guess both option 1 and 2 would be suitable for you.

Can we host multiple websites on S3 bucket?

Hosting several subdomains in the same S3 bucket can be a great solution if you want to save time and money. Using only one S3 bucket means saving money because Amazon charges you for the size and amount of buckets, so fewer buckets mean fewer expenses.

How many subdomains can you have on AWS?

The limits are not expressed directly in number of subdomains, but rather in number of records and hosted zones, among other things. Therefore, there is 10,000 records per hosted zone, but it can be increased. Also you can have 500 hosted zones per account.

How does subdomain routing work?

Typically, to route traffic for a subdomain, you create a record in the hosted zone that has the same name as the domain. For example, to route internet traffic for acme.example.com to a web server in your data center, you create a record named acme.example.com in the example.com hosted zone.


1 Answers

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.

like image 86
Alberto Spelta Avatar answered Oct 21 '22 09:10

Alberto Spelta