Search code examples
amazon-web-servicesamazon-s3amazon-cloudfront

Can I serve part of a static website from a different S3 bucket?


I have followed the AWS documentation to setup a simple static website:

  • S3 bucket mydomain.com -> contains the website files
  • Cloudfront distribution -> configured to serve mydomain.com with https (redirect http to https)
  • S3 bucket www.mydomain.com -> redirects to mydomain.com

Now, I have a second static site, which is independent of the main site. However I want to host it under mydomain.com/myproject/.

Currently I just copy the files for myproject into the same bucket in the folder /myproject/, but I was wondering if it would be feasible to have a separate bucket for myproject and redirect the URL to that bucket instead.

Could this be done and if so, how?


Solution

  • Yes, that can be done by having two behaviors in your CloudFront distribution, one mapping /* to the origin s3://mydomain.com and /myproject/* to the origin s3://myproject.

    Also, you can have both names as alternate CNAMEs for the distribution and use Route 53 ALIAS for them.