How to Deploy React App on Aws S3

Introduction Deploying a React application on AWS S3 is a popular and efficient way to host static websites and single-page applications (SPAs). Amazon Simple Storage Service (S3) provides scalable, secure, and cost-effective storage solutions, making it an ideal choice for front-end deployments. This tutorial will guide you through the entire process of deploying your React app on AWS S3, ensurin

Nov 17, 2025 - 11:32
Nov 17, 2025 - 11:32
 3

Introduction

Deploying a React application on AWS S3 is a popular and efficient way to host static websites and single-page applications (SPAs). Amazon Simple Storage Service (S3) provides scalable, secure, and cost-effective storage solutions, making it an ideal choice for front-end deployments. This tutorial will guide you through the entire process of deploying your React app on AWS S3, ensuring your application is accessible globally with minimal configuration.

Understanding how to deploy React apps on AWS S3 is essential for developers looking to leverage cloud infrastructure for scalability and reliability. This method eliminates the need for managing backend servers, reducing maintenance overhead and costs while providing fast content delivery through AWSs global infrastructure.

Step-by-Step Guide

Step 1: Prepare Your React Application

Before deploying, ensure your React app is production-ready. Use the create-react-app tool or your custom setup to build the app.

  • Navigate to your React project directory in the terminal.
  • Run the command: npm run build or yarn build.
  • This command creates a build folder containing optimized static files for deployment.

The build folder includes HTML, CSS, JavaScript, and media assets that your app needs to run.

Step 2: Create an S3 Bucket

Log in to your AWS Management Console and navigate to the S3 service.

  • Click on Create bucket.
  • Enter a unique and descriptive bucket name this name must be globally unique.
  • Choose the AWS Region closest to your target audience for lower latency.
  • Disable Block all public access to make your site publicly accessible.
  • Accept the warning about public access and confirm.
  • Click Create bucket.

Step 3: Configure Bucket for Static Website Hosting

Once your bucket is created, configure it to serve static website content.

  • Select your bucket and go to the Properties tab.
  • Scroll to Static website hosting and click Edit.
  • Choose Enable under Static website hosting.
  • Select Host a static website.
  • Set Index document to index.html.
  • Optionally, set an Error document (e.g., 404.html) if your app handles client-side routing.
  • Save changes.

The console will display your website endpoint URL, which you can use to access your deployed app.

Step 4: Set Bucket Policy for Public Access

To allow public read access to your files, you need to configure the bucket policy.

  • Go to the Permissions tab of your bucket.
  • Click Bucket policy and add the following JSON policy, replacing YOUR_BUCKET_NAME with your buckets name:

{

"Version": "2012-10-17",

"Statement": [

{

"Sid": "PublicReadGetObject",

"Effect": "Allow",

"Principal": "*",

"Action": "s3:GetObject",

"Resource": "arn:aws:s3:::YOUR_BUCKET_NAME/*"

}

]

}

Save the policy. This policy allows everyone to read objects in your bucket, making your website publicly accessible.

Step 5: Upload Build Files to S3 Bucket

Upload the contents of your React apps build folder to the S3 bucket.

  • You can use the AWS Management Console: Click Upload, select all files and folders inside the build directory, and start the upload.
  • Alternatively, use the AWS CLI for faster deployments:

aws s3 sync build/ s3://YOUR_BUCKET_NAME/ --delete

This command syncs your local build folder with the S3 bucket, deleting any files in the bucket not present locally.

Step 6: Test Your Deployed React App

Visit the S3 static website endpoint URL provided in Step 3. Your React app should load successfully.

If you encounter routing issues, especially with React Router, ensure your error document is set properly to index.html. This setup redirects all routes to your main HTML file, enabling client-side routing.

Step 7: (Optional) Configure a Custom Domain and SSL

For production environments, you might want to use a custom domain with HTTPS.

  • Use AWS Route 53 to manage DNS records.
  • Create an S3 bucket with the same name as your custom domain for redirect or hosting.
  • Use AWS CloudFront as a CDN to enable HTTPS and improve global delivery speeds.
  • Configure an SSL certificate using AWS Certificate Manager (ACM).

This advanced setup enhances security, branding, and performance.

Best Practices

Optimize Your React Build

Always optimize your React app before deployment by running production builds. Minimize bundle sizes through code splitting and lazy loading to improve load times.

Enable Caching and Versioning

Leverage cache-control headers to enable browser caching. Use unique file names via hashing (enabled by default in create-react-app) to ensure users receive the latest assets.

Secure Your S3 Bucket

While your bucket must be public for hosting, restrict write permissions strictly to trusted users and services. Regularly audit bucket policies and permissions.

Use CloudFront for Enhanced Performance

Deploy AWS CloudFront in front of your S3 bucket to reduce latency and provide HTTPS support out-of-the-box.

Set Up Logging and Monitoring

Enable S3 access logging and use AWS CloudWatch to monitor usage and spot potential issues early.

Tools and Resources

AWS Management Console

The web-based interface to manage and configure AWS services including S3, Route 53, CloudFront, and ACM.

AWS CLI

Command-line tool to automate and script deployment tasks, such as syncing files to S3.

Create React App

A popular React boilerplate that provides built-in support for production builds optimized for deployment.

React Router

Helps manage client-side routing. Requires specific S3 bucket error document configuration for SPA support.

CloudFront

A global content delivery network service by AWS that accelerates your app delivery and adds HTTPS support.

AWS Certificate Manager (ACM)

Provides free SSL/TLS certificates for use with AWS services like CloudFront.

Real Examples

Example 1: Simple React App Deployment

John created a personal portfolio using React. He built the app using npm run build, created an S3 bucket named john-portfolio-site, configured it for static web hosting, set a bucket policy for public access, and uploaded the build files. Within minutes, his portfolio was live globally at the S3 endpoint URL.

Example 2: Enterprise SPA With Custom Domain and HTTPS

A startup launched their React-based dashboard with client-side routing. They used AWS Route 53 to point a custom domain to an S3 bucket behind CloudFront. They secured the site with an ACM SSL certificate. This setup ensured fast, secure, and reliable delivery worldwide, with full control over DNS and HTTPS.

FAQs

Can I deploy a React app with backend APIs on S3?

No. S3 only hosts static files and cannot run server-side code. For backend APIs, use AWS Lambda, API Gateway, or other server-side services in conjunction with your React frontend.

How do I handle React Router routing on S3?

Configure the buckets error document to index.html. This setup ensures all navigation routes are served by React's client-side router.

Is AWS S3 free to use for hosting React apps?

AWS offers a free tier for S3 with limited storage and bandwidth. Beyond that, hosting costs are minimal and based on usage.

How do I update my React app after deployment?

Rebuild your app locally and sync the new build folder to your S3 bucket using the AWS CLI or manual upload. Using aws s3 sync ensures efficient updates.

Can I use a CDN with AWS S3?

Yes. AWS CloudFront is the recommended CDN for distributing your S3-hosted React app, improving performance and adding HTTPS support.

Conclusion

Deploying a React app on AWS S3 is a streamlined, cost-effective approach to hosting static web applications. By following this tutorial, developers can leverage AWSs robust cloud infrastructure to provide fast, scalable, and secure web experiences. Whether for personal projects or production-level deployments, AWS S3 combined with CloudFront and other AWS services offers a powerful solution for modern web application hosting.

Adopting best practices such as optimizing builds, configuring proper bucket policies, and enabling CDN distribution ensures your React app performs well and remains secure. With these skills, you can confidently deploy and maintain React applications on AWS S3.