Deploy a React app on AWS using Amazon S3 and CloudFront | Clickittech

Deploy a react app on AWS using Amazon S3 and CloudFront

Good news to share is that a react app means it is static. This means that once you had built all your files, there won’t be need of executing any instruction. Another news to share is that hosting a react app on Amazon S3 costs almost nothing… Yeih!! And finally, I would add the easiness that Amazon S3 provides to users at the moment of updating and deploying.

Through this next blog, you will find a tutorial of How to deploy a react app on AWS using Amazon S3 and CloudFront.

So, Let’s start!!

The entire Process

Step by Step

Create DNS Record

  1. Go to Route 53
Deploy-a-react-app-image-1
  1. Select your hosted zone and create a new record

Request SSL certificate

  1. Go to Certificate Manager
Deploy-a-react-app-image-2
  1. Click “Request a certificate”
Deploy-a-react-app-image-3
  1. Select “Request a public certificate” and click “request a certificate”
Deploy-a-react-app-image-4
  1. Choose a domain name, in this tutorial, we’re going to use a subdomain but you can choose a domain as well. Click “Next”.
Deploy-a-react-app-image-5
  1. Now we have to validate that we’re the owners of the domain, to do so, let’s select a validation method. You can choose two methods:
  • DNS Validation: AWS will provide you some records that you will need to add on your DNS settings.
  • Email Validation: AWS will send you an email with instructions to validate the SSL

On this step, if you don’t have access to your DNS records, it’s preferable to use the Email Validation, if not, you can use DNS validation method.

Deploy-a-react-app-image-6

Review your settings on the summary page at the end. Click “Confirm and request”. Make sure to follow the instructions of any of both methods, so we will have our SSL provided successfully and ready to use.

Deploy-a-react-app-image-7

You will see that our Request is in progress, go to your DNS settings or your email to validate your certificate. Finally, click “Continue”

Deploy-a-react-app-image-8

Once you have validated your SSL, you will notice that SSL has an “Issued” status, this means it’s ready to use!

Deploy-a-react-app-image-9

Create Bucket

  1. Go to Amazon S3
Deploy-a-react-app-image-10
  1. Click on “Create bucket”
Deploy-a-react-app-image-11
  1. Configure the bucket with desired settings, such as name, region, the rest of settings can use default values
Deploy-a-react-app-image-12
  1. When you have finished your bucket configuration, you will see a summary of your bucket settings. Finally, click on “Create bucket”
Deploy-a-react-app-image-13

 

Now we can leave S3 aside by the moment, let’s move to CloudFront. We are going to need a CloudFront distribution so we can link it to our bucket.

Create Distribution

    1. Go to Cloudfront
Deploy-a-react-app-image-14
  1. Create a new distribution, click “Create Distribution”
Deploy-a-react-app-image-15
  1. Select the Web type and click “Get started”
Deploy-a-react-app-image-16

The distribution settings are quite long, so let’s review each section individually

    1. On origin name, the list of buckets on your account will be listed, select the bucket previously created on the list
Deploy-a-react-app-image-17

On origin path, leave the path blank (we can modify this value later)

Deploy-a-react-app-image-18

Origin ID is automatically generated, do not modify it.

Change the setting from “No” to “Yes” on Restrict Bucket access

Deploy-a-react-app-image-19

Optional, assign a comment on the distribution, so we can know what’s the purpose for such distribution

Deploy-a-react-app-image-20

On Grant Read Permission on Bucket, select “Yes, Update Bucket Policy” (we’re changing the Bucket policy later but we need the Identity ID)

Deploy-a-react-app-image-21

Optional. Add Headers if needed.

Deploy-a-react-app-image-22

Let’s move to “Default Cache Behavior Settings” section, as a best practice, make sure to use the option “Redirect HTTP to HTTPS” to enable HTTPS.

Deploy-a-react-app-image-23

Leave the rest of settings by default, and move to Distribution Settings.

Deploy-a-react-app-image-24

On “Alternate Domain Names(CNames)” add your custom domain/subdomain, for this example, we’re using “myreactapp.clickittech.com”

Deploy-a-react-app-image-25

On SSL Certificate, choose the “Custom SSL Certificate” option and select the certificate that we created previously

Deploy-a-react-app-image-26

On “Default Root Object”, let’s set “index.html”, but it may vary depending on your app settings (generally it’s index.html)

Deploy-a-react-app-image-27

Make sure that Distribution State is “Enabled”

Deploy-a-react-app-image-28

Finally, click

Conclusion

Easy enough, right?

Well, now that you have a react app running within the AWS Cloud, you can definitely use all the features that the AWS Cloud has to offer you. Deploying a react app on AWS is not as difficult as you might be thinking, even though if you have any kind of obstacles, like How to use AWS Cloud Features or Which Cloud to choose? Then don’t doubt on contacting us, we want your infrastructure to be as optimized as possible.

We help digital companies like yours to deploy web applications on AWS.

  • Migrate your application to the Cloud.
  • Improve scalability and security of your infrastructure.
  • Guide your team to adopt AWS DevOps practices.