Automate React Site Deployments from GitHub to S3 & CloudFront

Rate this content
Bookmark

In this talk, I will demonstrate how to create a CI/CD pipeline for a React application in AWS. We'll pull the source code from GitHub and run tests against the application before deploying it to an S3 bucket for static site hosting. The site will then be distributed using CloudFront which will point to the S3 bucket. All of the infrastructure will be built using Terraform. In addition, I'll make use of Terragrunt to show how to create this setup for multiple environments.

This talk has been presented at DevOps.js Conf 2021, check out the latest edition of this Tech Conference.

FAQ

The main goal is to optimize release cycles for quality software in production by automating the tedious process of building pipelines for multiple environments, which enhances scalability and efficiency.

The tools used in the CI/CD pipeline setup include AWS CodeBuild, AWS CodePipeline, Terraform, and Terragrunt.

The pipeline pulls the source code from a GitHub repository, runs tests in the CI stage, and upon successful testing, deploys the static assets to an S3 bucket configured for static site hosting, which is then distributed using CloudFront.

Terragrunt acts as a Terraform wrapper that helps streamline the setup of infrastructure by keeping the codebase DRY (Don't Repeat Yourself) and simplifying the process of running repetitive infrastructure provisioning commands.

Multiple environment deployments are handled by configuring the pipeline to deploy to different environments using separate branches for each environment, such as production, UAT, and development.

To integrate a GitHub repository with AWS CodePipeline, you need to generate a personal access token in GitHub, save it securely, and configure AWS Secrets Manager to manage the token securely.

Using S3 for hosting static assets and CloudFront as a CDN allows for fast, scalable, and efficient distribution of content globally, improving the application's load times and user experience.

Lukonde Mwila
Lukonde Mwila
33 min
01 Jul, 2021

Comments

Sign in or register to post your comment.

Video Summary and Transcription

This Talk focuses on automating React deployments to S3 and CloudFront using a CICD pipeline in AWS. It covers setting up the pipeline, sourcing code from GitHub, and configuring infrastructure with Terraform and Terragrunt. The Talk also demonstrates the process of building and deploying a React application using AWS CodeBuild and CodePipeline. Overall, it provides a comprehensive overview of the tools and techniques involved in automating React deployments in AWS.

1. Introduction

Short description:

I'm going to be speaking to you about automating React deployments to S3 and CloudFront. The main motivation for doing this talk is there is an increasing shift for development teams to optimize their release cycles for quality software in production.

Hi, everyone. Thanks a lot for tuning in to my talk at DevOps.js conference 2021. I'm going to be speaking to you about automating React deployments to S3 and CloudFront. The main motivation for doing this talk is there is an increasing shift for development teams to optimize their release cycles for quality software in production. And CICD is the automated practice that helps software teams accomplish this. However, building pipelines can be a tedious process if you have to do that manually for multiple environments, as well as time consuming, and it doesn't scale very well, especially when this has to be done over and over again.

2. Setting up CICD Pipeline in AWS

Short description:

In this talk, I will walk you through setting up a CICD pipeline for React applications in AWS using codebuild and codepipeline. We will use Terraform and Terragrunt for infrastructure setup. I will demonstrate multiple environment deployment streams and show the final output of three different sites from the same code base. My name is Lukhan Demwila, a senior software engineer at Intellect and an AWS Container Hero.

So, in this talk, I want to go through a detailed code walkthrough of how to set up a CICD pipeline for React applications in AWS, and the CICD tooling that I'm going to be using is our codebuild and codepipeline. Now, the pipeline will pull the source code from a GitHub repository and run tests against that application in the CI stage before deploying it to the S3 bucket, which will then be configured to act as a static site for hosting, and in addition to that, this site will then be distributed using CloudFront and point to the S3 bucket as its origin.

So all of the infrastructure that will be built out will be done using Terraform. And in addition to that, I'm going to be making use of a tool called Terragrunt, which is a Terraform wrapper, and it really helps in terms of having a dry approach to actually just programming your infrastructure. And so that will be very helpful. As you see, we won't have as much code in our code base, even for our infrastructure, which will be very helpful. And this is one of the very good practices when it comes to building out resources like this. And so in the end, I will actually demonstrate for you a multiple environment deployment streams as well as the final output of three different sites from the same code base. And that is something that will be pretty cool to see once everything comes full circle.

Before we go any further, I'm going to start by introducing myself. I am Lukhan Demwila. A lot of people call me Luke. Some people do like to have a little bit of fun and go as far as calling me Skywalker. I'm a senior software engineer at Intellect. I'm also an AWS Container Hero and am five times AWS certified. I currently consult in the financial services sector, primarily working as a cloud and DevOps engineer. Previously, I was involved a lot in application development, both web and mobile, on SaaS products for startups. But I have since transitioned into the more cloud and DevOps space.

QnA

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

Levelling up Monorepos with npm Workspaces
DevOps.js Conf 2022DevOps.js Conf 2022
33 min
Levelling up Monorepos with npm Workspaces
Top Content
NPM workspaces help manage multiple nested packages within a single top-level package, improving since the release of NPM CLI 7.0. You can easily add dependencies to workspaces and handle duplications. Running scripts and orchestration in a monorepo is made easier with NPM workspaces. The npm pkg command is useful for setting and retrieving keys and values from package.json files. NPM workspaces offer benefits compared to Lerna and future plans include better workspace linking and adding missing features.
Automating All the Code & Testing Things with GitHub Actions
React Advanced Conference 2021React Advanced Conference 2021
19 min
Automating All the Code & Testing Things with GitHub Actions
Top Content
We will learn how to automate code and testing with GitHub Actions, including linting, formatting, testing, and deployments. Automating deployments with scripts and Git hooks can help avoid mistakes. Popular CI-CD frameworks like Jenkins offer powerful orchestration but can be challenging to work with. GitHub Actions are flexible and approachable, allowing for environment setup, testing, deployment, and custom actions. A custom AppleTools Eyes GitHub action simplifies visual testing. Other examples include automating content reminders for sharing old content and tutorials.
Fine-tuning DevOps for People over Perfection
DevOps.js Conf 2022DevOps.js Conf 2022
33 min
Fine-tuning DevOps for People over Perfection
Top Content
DevOps is a journey that varies for each company, and remote work makes transformation challenging. Pull requests can be frustrating and slow, but success stories like Mateo Colia's company show the benefits of deploying every day. Challenges with tools and vulnerabilities require careful consideration and prioritization. Investing in documentation and people is important for efficient workflows and team growth. Trust is more important than excessive control when deploying to production.
Why is CI so Damn Slow?
DevOps.js Conf 2022DevOps.js Conf 2022
27 min
Why is CI so Damn Slow?
Slow CI has a negative impact on productivity and finances. Debugging CI workflows and tool slowness is even worse. Dependencies impact CI and waiting for NPM or YARN is frustrating. The ideal CI job involves native programs for static jobs and lightweight environments for dynamic jobs. Improving formatter performance and linting is a priority. Performance optimization and fast tools are essential for CI and developers using slower hardware.
The Zen of Yarn
DevOps.js Conf 2022DevOps.js Conf 2022
31 min
The Zen of Yarn
Let's talk about React and TypeScript, Yarn's philosophy and long-term relevance, stability and error handling in Yarn, Yarn's behavior and open source sustainability, investing in maintenance and future contributors, contributing to the JavaScript ecosystem, open-source contribution experience, maintaining naming consistency in large projects, version consistency and strictness in Yarn, and Yarn 4 experiments for performance improvement.
Atomic Deployment for JS Hipsters
DevOps.js Conf 2024DevOps.js Conf 2024
25 min
Atomic Deployment for JS Hipsters
This Talk discusses atomic deployment for JavaScript and TypeScript, focusing on automated deployment processes, Git hooks, and using hard links to copy changes. The speaker demonstrates setting up a bare repository, configuring deployment variables, and using the post-receive hook to push changes to production. They also cover environment setup, branch configuration, and the build process. The Talk concludes with tips on real use cases, webhooks, and wrapping the deployment process.

Workshops on related topic

Deploying React Native Apps in the Cloud
React Summit 2023React Summit 2023
88 min
Deploying React Native Apps in the Cloud
WorkshopFree
Cecelia Martinez
Cecelia Martinez
Deploying React Native apps manually on a local machine can be complex. The differences between Android and iOS require developers to use specific tools and processes for each platform, including hardware requirements for iOS. Manual deployments also make it difficult to manage signing credentials, environment configurations, track releases, and to collaborate as a team.
Appflow is the cloud mobile DevOps platform built by Ionic. Using a service like Appflow to build React Native apps not only provides access to powerful computing resources, it can simplify the deployment process by providing a centralized environment for managing and distributing your app to multiple platforms. This can save time and resources, enable collaboration, as well as improve the overall reliability and scalability of an app.
In this workshop, you’ll deploy a React Native application for delivery to Android and iOS test devices using Appflow. You’ll also learn the steps for publishing to Google Play and Apple App Stores. No previous experience with deploying native applications is required, and you’ll come away with a deeper understanding of the mobile deployment process and best practices for how to use a cloud mobile DevOps platform to ship quickly at scale.
MERN Stack Application Deployment in Kubernetes
DevOps.js Conf 2022DevOps.js Conf 2022
152 min
MERN Stack Application Deployment in Kubernetes
Workshop
Joel Lord
Joel Lord
Deploying and managing JavaScript applications in Kubernetes can get tricky. Especially when a database also has to be part of the deployment. MongoDB Atlas has made developers' lives much easier, however, how do you take a SaaS product and integrate it with your existing Kubernetes cluster? This is where the MongoDB Atlas Operator comes into play. In this workshop, the attendees will learn about how to create a MERN (MongoDB, Express, React, Node.js) application locally, and how to deploy everything into a Kubernetes cluster with the Atlas Operator.
Azure Static Web Apps (SWA) with Azure DevOps
DevOps.js Conf 2022DevOps.js Conf 2022
13 min
Azure Static Web Apps (SWA) with Azure DevOps
WorkshopFree
Juarez Barbosa Junior
Juarez Barbosa Junior
Azure Static Web Apps were launched earlier in 2021, and out of the box, they could integrate your existing repository and deploy your Static Web App from Azure DevOps. This workshop demonstrates how to publish an Azure Static Web App with Azure DevOps.
Building Serverless Applications on AWS with TypeScript
Node Congress 2021Node Congress 2021
245 min
Building Serverless Applications on AWS with TypeScript
Workshop
Slobodan Stojanović
Slobodan Stojanović
This workshop teaches you the basics of serverless application development with TypeScript. We'll start with a simple Lambda function, set up the project and the infrastructure-as-a-code (AWS CDK), and learn how to organize, test, and debug a more complex serverless application.
Table of contents:        - How to set up a serverless project with TypeScript and CDK        - How to write a testable Lambda function with hexagonal architecture        - How to connect a function to a DynamoDB table        - How to create a serverless API        - How to debug and test a serverless function        - How to organize and grow a serverless application


Materials referred to in the workshop:
https://excalidraw.com/#room=57b84e0df9bdb7ea5675,HYgVepLIpfxrK4EQNclQ9w
DynamoDB blog Alex DeBrie: https://www.dynamodbguide.com/
Excellent book for the DynamoDB: https://www.dynamodbbook.com/
https://slobodan.me/workshops/nodecongress/prerequisites.html