Christiana
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Step-by-step guide on how to build and deploy a Serverless React application using AWS Amplify. ## Introduction: Serverless applications are becoming increasingly popular due to their scalability, cost-effectiveness, and ease of deployment. [`AWS Amplify`](https://aws.amazon.com/what-is-aws/?nc1=f_cc) is a great tool for building serverless apps. With its announcement in November 2017 as an open-source library for developers who want to develop cloud-based applications with `JavaScript` on the web or mobile platforms, `AWS Amplify` provides a comprehensive set of tools and services for building scalable, secure, and highly available cloud-powered applications. The [`AWS`](https://aws.amazon.com/) platform enables developers to easily create and deploy cloud-based applications in minutes with no server-side code by providing a comprehensive set of tools, including authentication, analytics, data storage, and more, to help developers quickly build and deploy apps. ## Benefits of building a serverless architecture: There are many benefits to building a serverless architecture. First, it eliminates the need for servers and other infrastructure, which results in a reduction in cost and maintenance. The architecture allows for faster scaling of services and increased reliability and availability. Additionally, serverless architecture provides developers with faster development cycles and more flexibility. Finally, serverless architecture helps to promote better collaboration and communication between development teams with its more manageable components. ## Overview of the steps involved in building and deploying a serverless React application using AWS Amplify. In this article, I will walk you through how to deploy a [`React.js`](https://reactjs.org/docs/getting-started.html) application using `AWS Amplify`. We will be: - Setting up the development environment: Here we will be installing and configuring the necessary tools and libraries to build the `React` application. - Creating and setting up a new `AWS Amplify` project: This step involves using the [`Amplify CLI`](https://docs.amplify.aws/cli/) to create a new project, configure the `backend services`, and set up the `authentication` and `authorization`. - Building the `React` application: This involves writing the `front-end code` for the application using `React` and integrating it with the backend services provided by `AWS Amplify` and testing the application locally. - Deploying the application: This involves using the `Amplify CLI` to push the changes to the `cloud`, where the application is automatically built and deployed to a scalable, secure, and highly available infrastructure. ## Prerequisites - `Node.js` - `React.js` - `Git` - `Amplify CLI` ## Setting up the development environment. Install [`Node.js`](https://nodejs.org/en/) first if you do not already have it downloaded and installed, as this is important to deploy your `React` app. Second, create your [`AWS` account](https://aws.amazon.com/premiumsupport/knowledge-center/create-and-activate-aws-account/) if you don’t have one yet, as you will need it to run `AWS Amplify`. ### Install and Set up Amplify CLI To install the `Amplify CLI`, run these commands ``` npm install -g @aws-amplify/cli amplify configure ``` After successfully installing and configuring the `amplify CLI`, an `AWS console` will open in your tab, ensure that you are logged in under the correct account and as an admin user. If you do not have an account yet, you can sign up. ![](https://paper-attachments.dropboxusercontent.com/s_E650D39A6F4B4291CD48B1D2FD629E8EACF88F34B16A0143093501D7618BB4FC_1675072199621_aws.JPG) Once you are signed in to AWS Console, `Amplify CLI` will ask you to create an [`AWS IAM`](https://aws.amazon.com/iam/) user: ``` Specify the AWS Region ? region: # Your preferred region Specify the username of the new IAM user: ? user name: # User name for Amplify IAM user Complete the user creation using the AWS console ``` You’ll be redirected to an interface where you will complete the wizard and create a user with `AdministratorAccess` in your account to provide AWS resources. Once the user is created, `Amplify CLI` will ask you to provide `accessKeyId` and `secretAccessKey` to connect `Amplify CLI` with our created `IAM` user: ![](https://paper-attachments.dropboxusercontent.com/s_E650D39A6F4B4291CD48B1D2FD629E8EACF88F34B16A0143093501D7618BB4FC_1675074327534_new.JPG) Congratulations! you have fully set up and configured your `AWS amplify`. ## Creating React App We will be developing a simple “Welcome to OpenReplay” `react` application. To get started, we will be creating a new `React` app using the `create-react-app` boilerplate. Open your terminal and run the command below. You can run `npm I -g create-react-app` first if you don't already have it installed. ``` npx create-react-app amplify-react-demo-app cd amplify-react-demo-app ``` Then run the command `npm start` to start our React App. ![](https://paper-attachments.dropboxusercontent.com/s_E650D39A6F4B4291CD48B1D2FD629E8EACF88F34B16A0143093501D7618BB4FC_1675071700087_react+app.JPG) Now that you have created a `react app`, open the `./src` folder and edit your code. ```javascript import "./App.css"; import { withAuthenticator, AmplifySignOut } from "@aws-amplify/ui-react"; function App() { return ( <div> <Welcome to OpenReplay /> </div> ); } export default withAuthenticator(App, true); ``` After successfully setting up the `React app`, it's time to initialize `Amplify` for our project. Run the command below from the root of the project. This command will set up our `AWS configuration` from scratch and generate a configuration file for our application's root directory. ``` $ amplify init ``` This command will prompt some information about the app and make the selections according to your config: ![](https://i.imgur.com/nwFBUDi.jpg) As soon as a new `Amplify project` is launched, the `CLI`: - created a file called `aws-exports.js` in the src directory that holds all the configuration for the services we create with Amplify - created a top-level directory called `Amplify` that contains our backend definition - modified the `.gitignore` file and added some generated files to the ignore list It will also create a new cloud project in the `AWS Amplify Console` which can be accessed by running `amplify console`. Now that the initialization is complete, here are some important `amplify` commands and workflows needed for your project: - `Amplify status`: This will display everything you have added already and show if it’s already configured or deployed locally. - `Amplify push`: This will update your cloud resources after you have made your category updates. This command will create local `back-end` resources and provision it in the `cloud`. - `Amplify Console`: This command will launch the browser directing you to your cloud project in the `AWS Amplify Console` and you can view your project status. - `Amplify Publish`: This command will build and publish both the backend and the frontend of the project. - `Amplify <category> add`: This command will add resources of a category to the cloud, you can easily add features like user login or a `back-end API`. ### Configuring Our React App To configure our `React` application, we will need to install `AWS Amplify` packages in our `React` app. To do this, run the command below in your app repository ``` $ sudo npm install aws-amplify @aws-amplify/ui-react ``` ### Authentication To add more control to our `React` application, let’s add an authentication function to our application. ![](https://paper-attachments.dropboxusercontent.com/s_E650D39A6F4B4291CD48B1D2FD629E8EACF88F34B16A0143093501D7618BB4FC_1675333289479_11111.JPG) ``` $ amplify add auth ``` Run the code above to add `authentication`, this will prompt some questions then select according to your configuration. ![](https://paper-attachments.dropboxusercontent.com/s_E650D39A6F4B4291CD48B1D2FD629E8EACF88F34B16A0143093501D7618BB4FC_1675334025738_111.JPG) The authentication module is currently set up for our application. The deployment of this configuration to our `AWS account` is still required. Fortunately for us, the `Amplify CLI` also handles this. Time to push the configuration. To do this, run the command below ``` $ amplify push ``` ![](https://paper-attachments.dropboxusercontent.com/s_E650D39A6F4B4291CD48B1D2FD629E8EACF88F34B16A0143093501D7618BB4FC_1675334358578_111.JPG) After pushing this configuration, the changes required to support our authentication module will be created in our AWS account and then deployed. Also, a configuration file called `aws-exports.js` will be created in our configured source (`./src`) directory. ### Configuring Amplify in Our React App Now we want to add `amplify` authentication service to our `React` app. In your `IDE`, open your `React` app folder and edit the `index.js` file by adding the code below to the header. ```javascript import amplify from ‘aws amplify’; import aws config from './aws-exports`; Amplify.configure(awsconfig); ``` ![](https://paper-attachments.dropboxusercontent.com/s_E650D39A6F4B4291CD48B1D2FD629E8EACF88F34B16A0143093501D7618BB4FC_1675335401289_111.JPG) Next is to add the Amplify Authenticator. Open the App.js file in the `./src`. folder and import `withAuthenticator` and wrap it into the `React` app. ```javascript import { withAuthenticator, AmplifySignOut } from "@aws-amplify/ui-react"; ... export default withAuthenticator(App); ``` It's great! Now time to test our app. We will Run the application using: ``` npm run start ``` The browser will launch with a secure page to sign in. Your app is now protected by `Amplify`. ![](https://paper-attachments.dropboxusercontent.com/s_E650D39A6F4B4291CD48B1D2FD629E8EACF88F34B16A0143093501D7618BB4FC_1675336798154_111.JPG) Create a new account ![](https://paper-attachments.dropboxusercontent.com/s_E650D39A6F4B4291CD48B1D2FD629E8EACF88F34B16A0143093501D7618BB4FC_1675336897288_111.JPG) You will receive an email with the confirmation code. Enter your verification code and your account is now created. Log in now and welcome to our secure React app ![](https://paper-attachments.dropboxusercontent.com/s_E650D39A6F4B4291CD48B1D2FD629E8EACF88F34B16A0143093501D7618BB4FC_1675337340831_annotely_image+7.jpeg) ![](https://paper-attachments.dropboxusercontent.com/s_E650D39A6F4B4291CD48B1D2FD629E8EACF88F34B16A0143093501D7618BB4FC_1675338027028_Add+a+subheading.png) ## Conclusion: In conclusion, building and deploying a Serverless `React` application using `AWS Amplify` can be a straightforward process with the right guidance. By following the step-by-step guide outlined in this article, you can leverage the power of `AWS Amplify` to create a robust, scalable, and cost-effective application that meets your business needs. With the knowledge gained from this guide, you can take the first steps toward building and deploying a successful `Serverless React` application. ## Resources: - [`GitHub`](https://github.com/Christianaojo/Reactamplify-App) - [`AWS Docs`](https://docs.amplify.aws/)

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully