Static websites with React and AWS

September 14, 2024

I've had some success with creating static websites using React and AWS. I created this website with those technologies, and I created PracticeJS (site no longer exists), which made the front page of Hacker News. On a high level, this is what works for me.

I use React and React Router to create a simple CMS that uses a JavaScript object to store the data for the website. Here is an example of what the code looks like.

I use an Amazon S3 bucket to host the website, setting the error document and index document to index.html so that it works right with React Router. I set up CloudFront to use the S3 bucket as its origin and set 404s to return as 200s.

I like to set up a custom SSL certificate with Certificate Manager and CloudFront. Then point the domain to CloudFront with Route 53.

I store the code for the website in GitHub and configure GitHub Actions to update the S3 bucket every time I push a commit. After everything is set up, I just need to update the JavaScript object and push the changes to update the website.

For more details about using S3 and CloudFront to host static websites see this whitepaper. Basically, it's a bulletproof way to build a website.