It seems there are kind of two ways to host a static website on S3/CloudFront.
- Create S3 bucket with full public access and Static Website set to Enabled + CloudFront config
- Create S3 bucket with no public access and Static Website set to Disabled + CloudFront config
What I don't like about (1) is the glaring "DO NOT DO THIS" red text for public access. But it works perfectly.
What I don't like about (2) is that I lose the Static Website set to Enabled benefits, like everything auto redirected to index.html
. Now I see there is a root origin
object in the CloudFront settings, but this only works for my base domain (eg mysite.com
). My site is an SPA and with (1) if I go to mysite.com/profile
it would correctly go to mysite.com/index.html
I think because of the 404 redirect I had setup. But with (2) going to mysite.com/profile
is not a 404 but rather an 403 access denied, which I don't think is smart to redirect like the 404.
So should I stick with option (1) even with the glaring red text about public access? Or is there a proper way to do an SPA without public access/static website hosting?