This repository is a boilerplate project for deploying a React application built with Vite to AWS S3 using GitHub Actions CI/CD.
It includes Production and Development environments, automated backups for Production, and a manual rollback system.
- Frontend: React + TypeScript + Vite
- Deployment: AWS S3 static hosting
- CI/CD: GitHub Actions
- Environments:
- Production (main branch): deployed to
S3_BUCKETwith automated backups toS3_BUCKET_BK - Development (develop branch): deployed to
S3_BUCKET_DEVwithout backups
- Production (main branch): deployed to
This setup allows you to have an active production version, a backup of each deploy, and a separate environment for testing.
aws_cicd_reactjs/
├─ .github/workflows/
│ ├─ deploy-prod.yml # Production workflow (with backup)
│ ├─ deploy-dev.yml # Development workflow (no backup)
│ ├─ list_backups.yml # Lists available production backups
│ └─ rollback.yml # Manual rollback workflow
├─ public/ # Static files
├─ src/ # React source code
├─ package.json
├─ yarn.lock
└─ vite.config.ts
- Push to
maintriggersdeploy-prod.yml. - GitHub Actions builds the React app using
yarn build, output goes todist/. - Backup: Current build is synced to
S3_BUCKET_BKwith timestamp formatYYYYMMDD-HHMMSS. - Active deploy: New build is synced to
S3_BUCKET, serving the live production site. - Rollback: Any backup can be restored using the
rollback.ymlworkflow.
- Push to
developtriggersdeploy-dev.yml. - GitHub Actions builds the app.
- Build is synced to
S3_BUCKET_DEV. - No backup is done for dev deployments.
For each bucket:
-
Enable Static Website Hosting:
- Index document:
index.html - Error document:
index.html(for SPA routing)
- Index document:
-
Set proper bucket policies for public access.
-
Secrets in GitHub:
AWS_ACCESS_KEY_IDAWS_SECRET_KEYAWS_REGIONS3_BUCKET→ Production bucketS3_BUCKET_BK→ Production backup bucketS3_BUCKET_DEV→ Development bucket
- Workflow:
rollback.yml - Workflow Dispatch Input:
backup_timestamp(formatYYYYMMDD-HHMMSS) - Steps:
- First, list available backups using
list_backups.yml. - Copy the desired timestamp from the log.
- Run
rollback.ymland input the timestamp. - The selected backup will be synced to the production bucket.
- First, list available backups using
Example AWS CLI commands if needed manually:
- List backups:
aws s3 ls s3://S3_BUCKET_BK/ - Restore a backup:
aws s3 sync s3://S3_BUCKET_BK/<timestamp>/ s3://S3_BUCKET/ --delete
- Clone the repository:
git clone https://github.com/cleberpereiradasilva/aws_cicd_reactjs.git
cd aws_cicd_reactjs
- Install dependencies:
yarn install
- Start development server:
yarn dev
- Build for production:
yarn build
- Push to the respective branch to trigger CI/CD workflows.
- Automated CI/CD → no manual S3 uploads required
- Backup management → every production deploy is preserved
- Manual rollback → easy restore of any previous version
- Separate Dev environment → safe testing without affecting production
- SPA-friendly →
index.htmlhandles routing
- Designed for small to medium projects
- Easy to expand with staging or multiple regions
- Ensure your AWS IAM user has S3 full access to the respective buckets
MIT License