6

Is there a way to configure a single CloudFront distribution with S3 so that hello.world.com will serve files from my-bucket.s3.amazonaws.com/hello, and foo.world.com will serve files from my-bucket.s3.amazonaws.com/foo?

I've added a new distribution with wildcard CNAME of *.world.com and I can add origins as described (by specifying root folder), but I don't know how to route requests based on subdomain. In the behaviour settings, there is path pattern but I don't think it applies to a domain, rather than the path to a file.

Basically I wanna do path rewrite to replace the first directory with the subdomain on a single cloudfront distribution with a single s3 bucket.

zavr
  • 2,049
  • 2
  • 18
  • 28
  • Have you tried creating separate CloudFront distributions – Karan Shah Jan 29 '17 at 14:24
  • 1
    This can be done, and I've been working on an answer. If you're familiar with my answers, they're [sometimes](http://stackoverflow.com/a/32289481/1695906) rather, um, thorough... so I need a bit of time. But it occurs to me that there are questions that might be relevant: how many wildcards are involved? <10? <100? <1000? More? Is there a reason you want this in a single distribution, instead of multiple? Using multiple distributions would not change the cost, and you could still do `foo.example.com/buzz >> example-bucket/foo/buzz` and `bar.example.com/buzz >> example-bucket/bar/buzz`. – Michael - sqlbot Jan 29 '17 at 18:00
  • @Michael-sqlbot what i want is to allow users register with a username, and store their uploads under user.website.com. I could create many cloudfront distributions but that would require using AWS API to create one for each user. Say I will have 1000 users for starters -- do you mind sharing your solution please mate? – zavr Feb 01 '17 at 18:43
  • @Michael-sqlbot did you ever write that answer? I have the exact same use-case and want users to be able to choose their own subdomain and then serve their content (static websites) from a folder in S3. – Prinzhorn Jun 21 '18 at 14:50
  • Never mind, this can likely be done in a few lines of Lambda@Edge. I'll post an answer when I'm done. But might take a while since I'm in research phase, not building yet. – Prinzhorn Jun 21 '18 at 14:56
  • @Prinzhorn I believe what you're looking for is in my answer at https://stackoverflow.com/a/49817210/1695906 – Michael - sqlbot Jun 21 '18 at 16:06
  • @Michael-sqlbot yes pretty much, thanks! – Prinzhorn Jun 22 '18 at 09:14

1 Answers1

0

I think I need to configure s3 rather than cloudfront, http://docs.aws.amazon.com/AmazonS3/latest/dev/HowDoIWebsiteConfiguration.html

zavr
  • 2,049
  • 2
  • 18
  • 28
  • http://stackoverflow.com/questions/29166016/cloudfront-rewrite-url-to-s3#comment68930936_29176968 – zavr Jan 29 '17 at 14:43
  • This doesn't accomplish the intended result. Redirect rules only examine the path, and they can only be used to `30X` redirect the browser, they do not do any kind of internal rewriting -- just external redirects. – Michael - sqlbot Jan 29 '17 at 17:48