Search code examples
reactjsamazon-s3amazon-ec2

S3 Amazon Static Website with React?


I built a website using ReactJs, and to see the website, I generally do npm start and go to localhost:3000 via a browser.

I now want to host this website on S3, but without an EC2 instance. My understanding is that npm is a process, so it is server-side, and therefore, I would need to purchase compute to actually deploy my website.

I found this tutorial that does not mention paying for EC2 instance compute time: https://www.fullstackreact.com/articles/deploying-a-react-app-to-s3/

However, they still use NPM which makes me confused.

My question is: is it possible to use React if I were to only use Static S3 Website, without compute, and if so - how do I bypass NPM process?

React - component in seperate script does not work

In the above post, user tried to make a hello-world app in react, but all of the answers point them in the direction of making a server serve the content. I thought react is a front-end thing and can run without server-side processes. Is this true? Can someone explain why node.js is necessary or is paired with react, and whether is is possible to use react on s3 without ec2 compute?


Solution

  • It's possible to host a static react site entirely on s3. In this case, you would use node/npm only as build tools and to run your development server (localhost:3000).

    npm would download your dependencies and you'd use node or gulp or webpack to build the assets into static files.

    Then you would upload the files to s3 where it would serve the static files.

    If you have some backend node code, then you would need to use ec2 or some other type of host. But if it's entirely static javascript, then there's no need for a node server.

    Here are some links that might help explain in more detail: