This is a sample repository that provides a secure, scalable, and automated multi-region infrastructure setup for a React frontend, Node.js backend, PostgreSQL database, and message queues. The setup also ensures GDPR/CCPA compliance by deploying region-specific resources and isolating data.
- React Frontend
- Built and deployed to AWS S3 or a CDN.
- Node.js Backend
- Dockerized and deployed on AWS ECS.
- PostgreSQL Database
- Hosted on AWS RDS within private subnets.
- Networking
- A secure VPC with private subnets for backend and database communication.
- CI/CD Pipeline
- Automated using GitHub Actions for continuous deployment.
- AWS CLI
- Terraform CLI
- Node.js (
>=16.x) and npm - Docker
-
Navigate to the
terraform/directory:cd terraform terraform init -
Update
variables.tfwith:- Region (
regionvariable) - VPC CIDR block (
vpc_cidrvariable) - Database credentials (
db_name,db_user,db_passwordvariables).
- Region (
Run the following command to deploy the infrastructure:
terraform applyThis deploys:
- VPC with private subnets.
- ECS for the backend.
- RDS PostgreSQL instance.
After deployment, Terraform will output critical details like:
- VPC ID
- Subnet IDs
- ECS cluster name
-
Navigate to the
frontend/directory:cd frontend npm install npm run build -
Deploy the
build/folder to an S3 bucket:aws s3 sync ./build s3://your-s3-bucket-name
If needed, configure a CloudFront distribution to serve the frontend globally.
- Navigate to the
backend/directory:cd backend docker build -t backend-app .
-
Authenticate with AWS ECR:
aws ecr get-login-password --region <region> | docker login --username AWS --password-stdin <account-id>.dkr.ecr.<region>.amazonaws.com
-
Push the image:
docker tag backend-app:latest <account-id>.dkr.ecr.<region>.amazonaws.com/backend-app:latest docker push <account-id>.dkr.ecr.<region>.amazonaws.com/backend-app:latest
Force an ECS service deployment with the new image:
aws ecs update-service --cluster your-cluster-name --service backend-service --force-new-deploymentThe repository includes a GitHub Actions workflow (.github/workflows/deploy.yml) for continuous deployment.
Add the following secrets in your GitHub repository:
AWS_ACCESS_KEY_IDAWS_SECRET_ACCESS_KEYAWS_REGION
Push changes to the main branch to automatically:
- Build and deploy the React frontend to S3.
- Build and deploy the Node.js backend to ECS.
For GDPR/CCPA compliance, deploy resources in specific regions:
-
Use Terraform workspaces to manage multiple environments:
terraform workspace new eu-region terraform apply
-
Ensure
regionis updated to the desired AWS region (e.g.,eu-west-1).
-
Data Residency:
- Ensure all resources (RDS, S3, ECS) are created in the same region.
- Enforce IAM policies to restrict cross-region access.
-
Encryption:
- Use AWS KMS to encrypt RDS, S3, and other sensitive data.
-
Monitoring:
- Use CloudWatch to monitor logs and metrics.
- Configure alerts for resource utilization thresholds.
multi-region-tenant-setup/
├── terraform/
│ ├── main.tf
│ ├── variables.tf
│ ├── modules/
│ │ ├── vpc/
│ │ ├── ecs/
│ │ └── rds/
├── frontend/
│ ├── src/
│ ├── public/
│ ├── package.json
│ └── build/
├── backend/
│ ├── app.js
│ ├── package.json
│ └── Dockerfile
└── .github/
└── workflows/
└── deploy.yml