2

Is it possible to serve two (or more) S3 buckets from a single domain using path to specify the origin bucket?

For example:

  • cdn.domain.com/images would be served from the bucket bucket-images
  • cdn.domain.com/files would be served from the bucket bucket-files

If possible, how to configure CloudFront distribution to make it work?

choxnox
  • 134
  • 1
  • 3
  • 16

2 Answers2

1

You can serve these different content from multiple bucket but as S3 ARN or the object URL is itself a FQDN ( A Domain Name) and CloudFront allows you to choose multiple origin per distribution. by changing it behaviour.

Please setup your CloudFront distribution follow this document: https://aws.amazon.com/premiumsupport/knowledge-center/cloudfront-distribution-serve-content/

Once done with this you can simply mapped this CloudFront URL with Rout 53.

Please let me know if you have any trouble while setting up this.

I can help you with this.

Prabhat Singh
  • 891
  • 8
  • 17
  • Ok, I read the article and I'm trying to make this work but to no avail and the fact that CF distribution takes ~30 mins. to update each change doesn't help at all. I'm trying to map `cdn.domain.com/images/profiles/{user-id}/profile.jpg` to S3 object with the key `profiles/{user-id}/profile.jpg` which is hosted on S3 bucket named `S3BucketImages`. How to do it properly? – choxnox Dec 04 '18 at 12:35
  • This answers my question: https://stackoverflow.com/questions/31567994/multiple-cloudfront-origins-with-behavior-path-redirection – choxnox Dec 04 '18 at 16:47
0

Not a direct solution, but a solution would be to use CORS. This allows you to host your websites content across multiple S3 buckets.

You can store your images in an image bucket, javascript in another and html somewhere else. CORS allows these buckets to access each other, as if they were in the same bucket.

However, you would have to do some more work with your websites routing and/or use an API gateway to have a specific bucket pertain to a certain path within your website.

Gary Holiday
  • 3,297
  • 3
  • 31
  • 72