4 ms·
Can you elaborate "CloudFront doesn't support index pages in subdirectories" and how does it not work? I'm not much into them these days but if I remember corr
by Brajeshwar 3y ago
Can you elaborate "CloudFront doesn't support index pages in subdirectories" and how does it not work?
I'm not much into them these days but if I remember correctly in the 4-5 years prior, they just works! In-fact, CloudFront was easier to serve static web assets than serving directly from S3.
Or have I misunderstood what you meant?
- VWWHFSfQ 3y agoYeah maybe I'm misunderstanding what this person is referring to, but cloudfront definitely supports index pages in any directory
- antihero 3y agoWhen was this added? I recall several years ago having to do this with edge lambdas. IE the it would happily resolve / to /index.html would be fine, but if you wanted to do /my-dir and have it resolve to /my-dir/index.html it would 404.
- Brajeshwar 3y agoNow that I'm curious because I remember facing no such issues. Cloudfront was my way of testing all of these scenarios to see what happens when the URL endpoint changes, etc. and then move to Akamai to scale up. Did some quick searches and I think there seems to be some kinks indeed and of course the solutions. Here are a few; - https://stackoverflow.com/questions/59634922/how-do-i-serve-index-html-in-subfolders-with-s3-cloudfront https://stackoverflow.com/questions/59634922/how-do-i-serve-... - https://aws.amazon.com/blogs/networking-and-content-delivery/implementing-default-directory-indexes-in-amazon-s3-backed-amazon-cloudfront-origins-using-cloudfront-functions/ https://aws.amazon.com/blogs/networking-and-content-delivery... Update/Edit: I think the setting to use correct S3 Endpoint makes a difference (which was indeed always my default way when I did). https://stackoverflow.com/questions/31017105/how-do-you-set-a-default-root-object-for-subdirectories-for-a-statically-hosted https://stackoverflow.com/questions/31017105/how-do-you-set-...
- antihero 3y agoYeah, I ended up writing a whole thing for it as part of my static website CDK construct. Here's the request edge lambda: https://github.com/radiosilence/cdk-static-web/blob/master/src/lambdas/request/index.ts https://github.com/radiosilence/cdk-static-web/blob/master/s... Here's the response edge lambda: https://github.com/radiosilence/cdk-static-web/blob/master/src/lambdas/response/index.ts https://github.com/radiosilence/cdk-static-web/blob/master/s... It's been a while since I've updated that project though. With nano-web for my current site (https://blit.cc https://blit.cc) I am just spinning up a free-tier unikernel instance on EC2 and using it as the CF origin. Possibly even more cost effective than S3, and far simpler. Response times for the "waiting" portion are usually around 5-10ms with CF and if I am going direct to the origin it's around 2-5ms
- deleted 3y ago[deleted]
- lukevp 3y agoIn a SPA, you want to change routes in the URL so you don’t break people’s expectations about being able to share deep links to specific pages, but those sites don’t really exist. Eg if your site is www.example.com and you have a SPA on there, and one of the pages is www.example.com/products, you want to still serve index.html from the root even though the /products path is not a real directory on your system. If you don’t serve for this URL then it’ll work fine locally but if someone hard-refreshes or shares the link, it won’t load.
- somethingAlex 3y agoIf you are using Cludfront with an S3 origin you can turn on static website hosting and specify a 404 fallback page[0] - which would then just be your index file. It will render your client code and let you show a 404 if it is indeed one. The problem is that essentially every time a user goes to the site it will be a 404 status code since they are probably not typing in example.com/index but this has pragmatically not been an issue for a wholly authenticated, private, B2B SaaS app. The marketing website is a separate subdomain. For a public site this is probably worse than returning 200s that should be 404s occasionally, though. [0]: https://docs.aws.amazon.com/AmazonS3/latest/userguide/CustomErrorDocSupport.html https://docs.aws.amazon.com/AmazonS3/latest/userguide/Custom...