How to deploy a simple React.js App with AWS

Setp by setp

Deploying a React app with AWS can be a bit overwhelming, especially if you're new to the platform. But with the right approach and guidance, you can easily deploy your React app to AWS in just a few steps. In this article, we will walk you through the process of deploying a React app with AWS, so let's get started!

Step 1: Create an AWS account

To deploy a React app with AWS, the first step is to create an AWS account. Go to the AWS website and click on the "Create an AWS account" button. Follow the prompts and fill in the required information, including your name, email address, and payment details. Once you've completed this step, you're ready to move on to the next step.

Step 2: Create an S3 Bucket

Amazon S3 (Simple Storage Service) is a cloud-based storage service that allows you to store and retrieve data from anywhere on the web. It is one of the most popular services offered by AWS, and we will use it to host our React app.

To create an S3 bucket, log in to your AWS account, and navigate to the S3 console. Click on the "Create bucket" button and fill in the required information, including a unique name for your bucket, region, and any other options you may need. Make sure to enable public access to your bucket to allow users to access your React app.

Step 3: Configure your S3 bucket

Once you've created your S3 bucket, you need to configure it to host your React app. To do this, follow these steps:

1.-Click on your bucket's name to open the bucket dashboard.

2.-Click on the "Properties" tab and select "Static website hosting."

3.-Select "Use this bucket to host a website."

4.-Enter the "Index document" and "Error document" values for your app. Typically, these values are "index.html" and "404.html," respectively.

5.-Click on the "Save" button to save your changes.

Step 4: Build your React app

Before we can deploy our React app to AWS, we need to build it. Open a terminal window and navigate to your app's root directory. Run the following command to build your app:

1 npm run build

This command creates a production-ready version of your React app in the "build" folder.

Step 5: Upload your React app to your S3 bucket

Now that we've built our React app, it's time to upload it to our S3 bucket. To do this, follow these steps:

1.-In your S3 bucket dashboard, click on the "Upload" button.

2.-Select the "build" folder containing your app's files.

3.-Click on the "Upload" button to upload your files to your bucket.

Step 6: Configure your S3 bucket policy

By default, your S3 bucket is not configured to allow public access. To allow users to access your React app, you need to configure your bucket policy. To do this, follow these steps:

1.-In your S3 bucket dashboard, click on the "Permissions" tab.

2.-Click on the "Bucket Policy" button and paste the following policy:

1 2 3 4 5 6 7 8 9 10 11 12 { "Version":"2012-10-17", "Statement":[ { "Sid":"PublicReadGetObject", "Effect":"Allow", "Principal": "*", "Action":["s3:GetObject"], "Resource":["arn:aws:s3:::your-bucket-name/*"] } ] }

Make sure to replace "your-bucket-name" with the name of your S3 bucket.

Step 7: Test your React app

To access your React app from the browser, you will need to obtain the endpoint URL of your S3 bucket. To do this, follow these steps:

1.-In your S3 bucket dashboard, click on the "Properties" tab.

2.-Scroll down to the "Static website hosting" section and locate the "Endpoint" URL.

3.-Copy the Endpoint URL.

Now, paste the Endpoint URL into your browser's address bar and press Enter. Your React app should load in the browser, and you can start using it. If you encounter any issues, double-check your S3 bucket configuration and bucket policy to ensure that your app is configured correctly.

Thank you for taking the time to read this article on how to deploy a React app with AWS. I hope that this guide has been helpful in assisting you with deploying your app and that you've found it to be clear and easy to follow. If you have any questions or encounter any issues during the deployment process, feel free to reach out to AWS support or consult their extensive documentation. Good luck with your app deployment, and happy coding!

More Posts
Created by Roberto Espinoza