Getting Started with AWS

Build a Full-Stack React Application

Create a simple web application using AWS Amplify

Module 1: Deploy and Host a React App

In this module, you will create a React application and deploy it to the cloud using the AWS Amplify web hosting service

Overview

AWS Amplify provides a Git-based CI/CD workflow for building, deploying, and hosting single-page web applications or static sites with serverless backends. Upon connecting to a Git repository, Amplify determines the build settings for both the frontend framework and any serverless backend resources configured with the Amplify CLI, and automatically deploys updates with every code commit.

In this module, we will begin by creating a new React application and push it to a GitHub repository. Then, we will connect the repository to AWS Amplify web hosting and deploy it to a globally available content delivery network (CDN) hosted on an amplifyapp.com domain. Next, we will demonstrate continuous deployment capabilities by making changes to the React application and push a new version to the main branch, which will automatically kick off a new deployment.

What you will accomplish

In this module, you will:
  • Create a React application
  • Initialize a GitHub repository
  • Deploy your app with AWS Amplify
  • Implement code changes and redeploy your app

Key concepts

React application – React is a JavaScript web application library that enables developers to quickly build performant single-page applications.

Git – A version control system that allows developers to store files and maintain and update relationships between files and directories, versions, and changes to the files.

 Time to complete

10 minutes

 Services used

Implementation

  • The easiest way to create a React application is by using the command create-react-app. Install this package using the following command in your command prompt or terminal:

    npx create-react-app amplifyapp
    cd amplifyapp
    npm start
  • In this step, you will create a GitHub repository and commit your code to the repository. You will need a GitHub account to complete this step—if you do not have an account, sign up here.

    a. Create a new GitHub repo for your app.

    b. Open a new terminal and navigate back to your app's root folder, for example, amplifyapp.

    c. Using create-react-app will automatically initialize the git repo and make an initial commit. If you are trying to deploy an existing React application where git has not been initialized, make sure to input the following commands before continuing:

    git init
    git add .
    git commit -m "initial commit"

    d. If you have never used GitHub on your computer, follow these steps before continuing to allow connection to your account.

    Push the application to the new GitHub repo by executing the following commands in your command line interface:

    git remote add origin git@github.com:username/reponame.git
    git branch -M main
    git push -u origin main
  • Open the AWS Management Console in a new browser window, so you can keep this step-by-step guide open. When the screen loads, enter your user name and password to get started. Then enter Amplify in the search bar and select AWS Amplify to open the service console.

  • In this step, you will connect the GitHub repository you just created to the AWS Amplify service. This will enable you to build, deploy, and host your app on AWS.

    a. In the AWS Amplify service console, select Get Started under Amplify Hosting.

    b. Select GitHub as the repository service and select Continue.

    c. Authenticate with GitHub and return to the Amplify console. Choose the repository and main branch you created earlier, then select Next.

    d. Accept the default build settings and select Next.

    e. Review the final details and choose Save and deploy.

    f. AWS Amplify will now build your source code and deploy your app at https://...amplifyapp.com.

    g. Once the build completes, select the thumbnail to see your web app up and running live. 

  • In this step, you will make some changes to the code using your text editor and push the changes to the main branch of your app.

    a. Edit src/App.js with the code below and save.

    import React from 'react';
    import logo from './logo.svg';
    import './App.css';
    
    function App() {
      return (
        <div className="App">
          <header className="App-header">
            <img src={logo} className="App-logo" alt="logo" />
            <h1>Hello from V2</h1>
          </header>
        </div>
      );
    }
    
    export default App;

    b. Push the changes to GitHub in the command prompt (Windows) or terminal (macOS) to automatically kick off a new build: 

    git add .
    git commit -m “changes for v2”
    git push origin main

    c. Once the build is complete, select the thumbnail in the AWS Amplify console to view your updated app.

Conclusion

You have deployed a React application in the AWS Cloud by integrating with GitHub and using AWS Amplify. With AWS Amplify, you can continuously deploy your application in the cloud and host it on a globally available CDN.

Next, we will create a local version of the app to continue development and add new features.

Was this page helpful?

Initialize Local App