3
votes

I have an Angular app that is currently server-side rendered by .Net Core. I want to change my build process to prerender almost all of my site and push all the static files to an Amazon S3 bucket and point my domain name there instead. However, I cannot prerender all of my website (at least not yet).

I found how I can return my index.html for any pages which are not prerendered and don't exist in the S3 bucket, which will allow me to client-side render the page, but I want to take it a step further and server-side render the page on-the-fly.

Is there a way I can use the S3 site as a reverse proxy that will fetch the SSR page from my .Net Core site if the prerendered version does not exist?

Update: Just to be clear, the S3 bucket will be for a CloudFront CDN, so setting up a proxy in front of the S3 bucket probably isn't an option.

Update 2: I found I can deliver dynamic content via CloudFront, but I don't want everything to be dynamic. I want any static content (like my prerendered pages) to be served from a cheap S3 bucket and only serve dynamic content from my more expensive EC2 instance if the static version doesn't exist.

1
You can probably do this by setting up a reverse proxy using an EC2 instance between the S3 bucket and CloudFront, and configure the middleware so it renders missing pages.iBug

1 Answers

1
votes

The short answer is No. You cannot use S3 as a reverse proxy to fetch the missing objects from another source.

But, if your static content can easily be identified by path, you could create two origins in CloudFront, one for static and one for dynamic content, and serve them using different behavior/path pattern combination for each origin: S3 bucket for your static content and maybe a custom origin for your dynamic content (hosted on EC2).

You may also want to look at CloudFront Origin Failover, although it's designed for supporting high availability scenarios it may accomodate your use case. You would also need two origins, primary and failover (for static & dynamic content). See more information here: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/high_availability_origin_failover.html