Skip to content

SubhanshuMG/multi-region-tenant-setup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Multi-Region, Multi-Tenant Infrastructure Setup

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.


Components

  1. React Frontend
    • Built and deployed to AWS S3 or a CDN.
  2. Node.js Backend
    • Dockerized and deployed on AWS ECS.
  3. PostgreSQL Database
    • Hosted on AWS RDS within private subnets.
  4. Networking
    • A secure VPC with private subnets for backend and database communication.
  5. CI/CD Pipeline
    • Automated using GitHub Actions for continuous deployment.

1. Prerequisites


2. Infrastructure Deployment

Step 1: Initialize Terraform

  1. Navigate to the terraform/ directory:

    cd terraform
    terraform init
  2. Update variables.tf with:

    • Region (region variable)
    • VPC CIDR block (vpc_cidr variable)
    • Database credentials (db_name, db_user, db_password variables).

Step 2: Deploy Resources

Run the following command to deploy the infrastructure:

terraform apply

This deploys:

  • VPC with private subnets.
  • ECS for the backend.
  • RDS PostgreSQL instance.

Step 3: Retrieve Outputs

After deployment, Terraform will output critical details like:

  • VPC ID
  • Subnet IDs
  • ECS cluster name

3. React Frontend Deployment

Step 1: Build Frontend

  1. Navigate to the frontend/ directory:

    cd frontend
    npm install
    npm run build
  2. Deploy the build/ folder to an S3 bucket:

    aws s3 sync ./build s3://your-s3-bucket-name

Step 2: Set Up CloudFront (Optional)

If needed, configure a CloudFront distribution to serve the frontend globally.


4. Node.js Backend Deployment

Step 1: Build Docker Image

  1. Navigate to the backend/ directory:
    cd backend
    docker build -t backend-app .

Step 2: Push Docker Image to ECR

  1. Authenticate with AWS ECR:

    aws ecr get-login-password --region <region> | docker login --username AWS --password-stdin <account-id>.dkr.ecr.<region>.amazonaws.com
  2. 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

Step 3: Update ECS Service

Force an ECS service deployment with the new image:

aws ecs update-service   --cluster your-cluster-name   --service backend-service   --force-new-deployment

5. CI/CD with GitHub Actions

The repository includes a GitHub Actions workflow (.github/workflows/deploy.yml) for continuous deployment.

Step 1: Configure Secrets

Add the following secrets in your GitHub repository:

  • AWS_ACCESS_KEY_ID
  • AWS_SECRET_ACCESS_KEY
  • AWS_REGION

Step 2: Trigger Pipeline

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.

6. Region-Specific Deployment

For GDPR/CCPA compliance, deploy resources in specific regions:

  1. Use Terraform workspaces to manage multiple environments:

    terraform workspace new eu-region
    terraform apply
  2. Ensure region is updated to the desired AWS region (e.g., eu-west-1).


7. Privacy and Security

  1. Data Residency:

    • Ensure all resources (RDS, S3, ECS) are created in the same region.
    • Enforce IAM policies to restrict cross-region access.
  2. Encryption:

    • Use AWS KMS to encrypt RDS, S3, and other sensitive data.
  3. Monitoring:

    • Use CloudWatch to monitor logs and metrics.
    • Configure alerts for resource utilization thresholds.

8. Directory Structure

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published