2

I need to create a service that allows users to publish a static page in a custom subdomain. I've never done this so excuse me if the question sounds a bit too basic.

To do so, I would like to host all those static files in something like Amazon S3 or Google cloud Storage to separate it from my server, make it scalable and secure it all.

While considering Amazon S3 I noticed a user account is limited to 100 buckets. So I can't just use a bucket per customer.

I guess, I could use 1 bucket for multiple users by just creating folders in it and pointing each folder to a different subdomain?

Does this sound like a proper solution to this problem?

I was reading you can't just point any subdomain to any bucket? Both names should be the same? Wouldn't this be a problem here?

Alvaro
  • 40,778
  • 30
  • 164
  • 336
  • 1
    You can use a CloudFront distribution, a single bucket, and a Lambda@Edge trigger for this. The content is served from a path beginning with the subdomain. https://stackoverflow.com/a/49817210/1695906 – Michael - sqlbot Mar 10 '20 at 01:23
  • Thanks for that I'll take a look at it!! – Alvaro Mar 10 '20 at 18:18
  • @Michael-sqlbot would I have to create the subdomains from my hosting's cpanel API ? Or is this something I would also have to do from Amazon Services ? – Alvaro Mar 10 '20 at 23:11
  • You could point a `*.example.com` wildcard DNS record to the endpoint hostname of the CloudFront distribution, and configure `*.example.com` as the Alternate Domain Name in the distribution settings. Any subdomain would then work. `foo.example.com/cat.jpg` would be served from the object `foo/cat.jpg` in the bucket. – Michael - sqlbot Mar 12 '20 at 01:53

1 Answers1

3

You can do it, one bucket, one folder per website - but you would then use aws cloudfront to serve the data instead of s3 directly - the custom domain would point to cloudfront, and cloudfront would have a different distribution for each website (which would be the matching folder under the single bucket) - not as complicated as it sounds, and is probably the best way to do what you want.

You are correct though, there is a 100 bucket limit (without requesting more), and the bucket name must match the domain name exactly (which can be a problem), but those restrictions don't apply if you use the cloudfront solution I mentioned above.

E.J. Brennan
  • 45,870
  • 7
  • 88
  • 116
  • Is Cloudfront something we have to pay separatel? You said the "custom domain will point to cloudfront", you mean, the custom "subdomain" ? Can i have the main domain pointing to another hosting?For example "demo.com" pointing to host A (my current one) and test.demo.com pointing to Cloudfron? – Alvaro Mar 09 '20 at 22:25
  • Yes, and yes - yes, the main domain and subdomains can all point to different places, and yes, you pay for cloudfront separately (very inexpensive in my experience for low to medium traffic sites) – E.J. Brennan Mar 10 '20 at 09:17