Voiced by Amazon Polly |
Overview
In the fast-paced world of front-end development, automation isn’t a luxury but a necessity. Manual deployment of React apps can be time-consuming and error-prone. In this tutorial, we’ll set up a CI/CD pipeline for a React application using AWS CodePipeline, CodeBuild, and S3, ensuring smooth, automatic deployments from GitHub to the cloud.
In this guide, you will learn how to automate the deployment of your React app using AWS services so your updates go live instantly, reliably, and at scale.
Pioneers in Cloud Consulting & Migration Services
- Reduced infrastructural costs
- Accelerated application deployment
Why Use CI/CD for React with AWS CodePipeline?
AWS CodePipeline is Amazon’s managed CI/CD service that allows you to automate this entire process. When combined with AWS CodeBuild and Amazon S3, it enables a smooth deployment pipeline for React apps, ensuring:
- Faster release cycles
- Fewer manual errors
- Automatic builds and deployments from GitHub
- Easy rollback or re-deployment options
Step-by-Step Guide
Step 1: Prepare Your React App
Make sure your project has a working build setup.
Check your package.json for the build script:
1 2 3 4 |
"scripts": { "start": "react-scripts start", "build": "react-scripts build" } |
Create a buildspec.yml file in the project root:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
version: 0.2 phases: install: runtime-versions: nodejs: 18 commands: - npm install build: commands: - npm run build artifacts: files: - '**/*' base-directory: build |
Step 2: Create an Amazon S3 Bucket for Hosting
- Go to Amazon S3 > Create Bucket
- Use a globally unique name like my-react-app-deployments
- After creation:
- Enable Static website hosting in Properties
- Set:
- Index document: html
- Error document: html (for React routers)
- (Optional) Make it public (for dev) or use CloudFront + OAI for production
Step 3: Set Up AWS CodeBuild - Go to CodeBuild > Create build project
- Set:
- Name: react-build-project
- Source provider: GitHub → connect your repo
- Environment image: Managed image → Ubuntu, Node.js 18
- Buildspec: Select “Use a buildspec.yml file”
- Set Artifacts:
- Type: Amazon S3
- Bucket: Choose your S3 bucket
- IAM Role:
- Let AWS create a role or attach permissions:
- s3:PutObject
- logs:*
- Let AWS create a role or attach permissions:
Step 4: Create AWS CodePipeline Pipeline
- Go to AWS CodePipeline > Create pipeline
- Pipeline name: react-ci-pipeline
- Choose service role: Allow AWS to create or use existing one
Stage 1: Source
- Provider: GitHub
- Connect GitHub account and select repo + branch
Stage 2: Build
- Provider: AWS CodeBuild
- Select the build project you created earlier
Stage 3: Deploy
- Provider: Amazon S3
- Select the bucket you created for static hosting
- Leave file name empty (it deploys all artifacts)
Step 5: Push Changes and Watch the Magic
Now go to your local project and make a change:
1 2 3 4 5 |
bash CopyEdit git add . git commit -m "Update UI" git push origin main |
- Open AWS CodePipeline
- Your pipeline should start automatically
Once it completes, visit your Amazon S3 website endpoint to see the deployed React app.
Conclusion
By setting up a CI/CD pipeline with AWS CodePipeline, AWS CodeBuild, and Amazon S3, you have taken a huge step toward modern, automated front-end development. Every time you push a change to GitHub, your React app is rebuilt and deployed without any manual intervention.
This not only speeds up your development workflow but also ensures consistency, scalability, and reliability in your deployments. Whether you’re working solo or in a team, this setup lays the foundation for rapid iteration and continuous delivery, key pillars of modern DevOps practices.
Drop a query if you have any questions regarding Amazon S3 and we will get back to you quickly.
Making IT Networks Enterprise-ready – Cloud Management Services
- Accelerated cloud migration
- End-to-end view of the cloud environment
About CloudThat
CloudThat is an award-winning company and the first in India to offer cloud training and consulting services worldwide. As a Microsoft Solutions Partner, AWS Advanced Tier Training Partner, and Google Cloud Platform Partner, CloudThat has empowered over 850,000 professionals through 600+ cloud certifications winning global recognition for its training excellence including 20 MCT Trainers in Microsoft’s Global Top 100 and an impressive 12 awards in the last 8 years. CloudThat specializes in Cloud Migration, Data Platforms, DevOps, IoT, and cutting-edge technologies like Gen AI & AI/ML. It has delivered over 500 consulting projects for 250+ organizations in 30+ countries as it continues to empower professionals and enterprises to thrive in the digital-first world.
FAQs
1. Should I make my Amazon S3 bucket public to host a React app?
ANS: – Not necessarily. Making the bucket public is fine for development, but for production, it’s better to use Amazon CloudFront with Origin Access Identity (OAI) or Origin Access Control (OAC). This provides secure and performant access without exposing your Amazon S3 bucket directly to the public internet.
2. Can I run tests as part of the build process?
ANS: – Yes! You can add test commands in the buildspec.yml file. For example:
1 2 3 4 5 6 7 8 |
yaml CopyEdit build: commands: - npm run test - npm run build |
WRITTEN BY Shreya Shah
Comments