How to Deploy A react Application into AWS Amplify

React has become one of the most popular front-end development frameworks, thanks to its versatility and ease of use. One of the most important steps in building a React application is deploying it. There are a number of ways to deploy a React app, but one of the easiest and most efficient is to use AWS Amplify.

AWS Amplify is a development platform that provides a suite of services to build and deploy applications. With Amplify, developers can easily set up a scalable cloud backend, connect to multiple data sources, and deploy their applications to a variety of platforms, including web, mobile, and desktop.

In this blog, we will take a closer look at how to deploy a React application into AWS Amplify.

Prerequisites
Before we begin, there are a few things that you will need:

A React application that is ready for deployment.
An AWS account.
A GitHub account.

Step 1: Set up an Amplify App

The first step in deploying a React app with Amplify is to create a new Amplify app. To do this, go to the AWS Amplify Console and click on the “Get Started” button.

Next, you will be prompted to connect a Git repository. If you don’t already have a Git repository set up for your React application, you can create one on GitHub or another Git provider.

Once you have connected your Git repository, you will need to select the branch that you want to deploy. In most cases, you will want to select the master branch.

After you have selected your branch, you will be asked to provide a name for your Amplify app. This can be anything you like, but it’s a good idea to choose a name that reflects the purpose of your app.

Once you have provided a name for your app, click on the “Create App” button to create your new Amplify app.

Step 2: Configure the Build Settings

Now that you have created your Amplify app, you will need to configure the build settings. This will tell Amplify how to build and deploy your React application.

To configure the build settings, click on the “App Settings” button in the left-hand menu of the Amplify Console. Then, click on the “Build Settings” tab.

In the Build Settings tab, you will see a number of different options for configuring your build. The most important setting is the build command. This is the command that Amplify will use to build your React application.

In most cases, the build command for a React application will be:

npm run build

If your React application uses a different build command, make sure to enter it here.

You can also configure other build settings, such as the build output directory, the environment variables, and the build timeout. Once you have configured your build settings, click on the “Save” button to save your changes.

Step 3: Set up the Deployment Environment

Before you can deploy your React application, you will need to set up the deployment environment. This is the environment where your application will be deployed, such as a production environment or a staging environment.

To set up the deployment environment, click on the “Environments” button in the left-hand menu of the Amplify Console. Then, click on the “Add Environment” button to add a new environment.

You will need to provide a name for your environment, such as “production” or “staging”. You can also choose to copy settings from an existing environment if you have one set up.

Once you have provided a name for your environment, click on the “Create Branch” button to create a new branch for your environment.

Step 4: Deploy your React Application

Now that you have set up your Amplify app and configured the build settings and deployment environment, you are ready to deploy your React application.

To deploy your application, go to your Git repository and push your changes to the master branch. This will trigger the build process in Amplify, which will build and deploy your React application to the environment that you specified.

You can monitor the progress of the build and deployment in the Amplify Console. Once the deployment is complete, you will be able to view your deployed React application by clicking on the “View Website” button in the Amplify Console.

Conclusion

Deploying a React application to AWS Amplify is a straightforward process that can be completed in just a few steps. By following the steps outlined in this blog, you can easily set up an Amplify app, configure the build settings and deployment environment, and deploy your React application with ease.

AWS Amplify provides a powerful platform for building and deploying applications, with a wide range of services that can help you to scale your application and improve its performance. Whether you are building a small personal project or a large enterprise application, AWS Amplify is a great choice for deploying your React application.

Here is another sample build example given for aws codecommit

version: 1
frontend:
  phases:
    preBuild:
      commands:
        - git config --global credential.helper '!aws codecommit credential-helper $@'
        - git config --global credential.UseHttpPath true
        - yarn install
    build:
      commands:
        - yarn run build
  artifacts:
    baseDirectory: build
    files:
      - '**/*'
  cache:
    paths:
      - node_modules/**/*

Atiqur Rahman

I am MD. Atiqur Rahman graduated from BUET and is an AWS-certified solutions architect. I have successfully achieved 6 certifications from AWS including Cloud Practitioner, Solutions Architect, SysOps Administrator, and Developer Associate. I have more than 8 years of working experience as a DevOps engineer designing complex SAAS applications.

Leave a Reply