Skip to content

Latest commit

 

History

History
202 lines (188 loc) · 12.8 KB

File metadata and controls

202 lines (188 loc) · 12.8 KB

MongoDB Volume Cloning Architecture

System Architecture

┌─────────────────────────────────────────────────────────────────────┐
│                          AWS Cloud (us-west-2)                      │
│                                                                     │
│  ┌──────────────────────────┐      ┌──────────────────────────┐     │
│  │   Production EC2         │      │    Staging EC2           │     │
│  │  MongoDB-production      │      │   MongoDB-staging        │     │
│  │                          │      │                          │     │
│  │  ┌────────────────────┐  │      │  ┌────────────────────┐  │     │
│  │  │ Root Volume (8GB)  │  │      │  │ Root Volume (8GB)  │  │     │
│  │  │    /dev/nvme0n1    │  │      │  │    /dev/nvme0n1    │  │     │
│  │  └────────────────────┘  │      │  └────────────────────┘  │     │
│  │                          │      │                          │     │
│  │  ┌────────────────────┐  │      │  ┌────────────────────┐  │     │
│  │  │ Data Volume (20GB) │  │      │  │ Data Volume (20GB) │  │     │
│  │  │    /dev/nvme1n1    │  │      │  │    /dev/nvme1n1    │  │     │
│  │  │  /data/mongodb     │  │      │  │  /data/mongodb     │  │     │
│  │  │                    │  │      │  │                    │  │     │
│  │  │ ┌────────────────┐ │  │      │  │ ┌────────────────┐ │  │     │
│  │  │ │ userdb         │ │  │      │  │ │ userdb         │ │  │     │
│  │  │ │   users (PII)  │ │  │      │  │ │   users (ANON) │ │  │     │
│  │  │ │   10 records   │ │  │      │  │ │   10 records   │ │  │     │
│  │  │ └────────────────┘ │  │      │  │ └────────────────┘ │  │     │
│  │  └────────────────────┘  │      │  └────────────────────┘  │     │
│  │         │                │      │         ▲                │     │
│  └─────────┼────────────────┘      └─────────┼────────────────┘     │
│            │                                 │                      │
│            │                                 │                      │
│            ▼                                 │                      │
│     ┌─────────────┐                          │                      │
│     │  Snapshot   │────────────────────────-─┘                      │
│     │  (20GB)     │  Clone Process                                  │
│     └─────────────┘                                                 │   
│                                                                     │   
└───────────────────────────────────────────────────────────────────--┘
          ▲
          │
          │ AWS CLI / Ansible Commands
          │
    ┌─────┴──────┐
    │  Executor  │
    ├────────────┤
    │ • Local    │
    │ • GHA      │
    └────────────┘

Data Flow

1. SNAPSHOT CREATION
   ┌──────────────┐
   │ Production   │
   │ Data Volume  │
   │    (20GB)    │
   └──────┬───────┘
          │
          │ aws ec2 create-snapshot
          ▼
   ┌──────────────┐
   │  Snapshot    │
   │ (EBS Snap)   │
   └──────┬───────┘

2. VOLUME CREATION
          │
          │ aws ec2 create-volume
          ▼
   ┌──────────────┐
   │  New Volume  │
   │    (20GB)    │
   └──────┬───────┘

3. VOLUME SWAP
          │
          │ Detach old + Attach new
          ▼
   ┌──────────────┐
   │   Staging    │
   │     EC2      │
   │  (Attached)  │
   └──────┬───────┘

4. MOUNT & START
          │
          │ mount + systemctl start
          ▼
   ┌──────────────┐
   │   MongoDB    │
   │   Running    │
   └──────┬───────┘

5. ANONYMIZATION
          │
          │ mongosh < anonymize.js
          ▼
   ┌──────────────┐
   │   PII Data   │
   │  Anonymized  │
   └──────────────┘

AWS Resource Relationships

┌─────────────────────────────────────────────────────────────┐
│                        AWS Account                          │
│                                                             │
│  ┌──────────────┐         ┌──────────────┐                  │
│  │     VPC      │         │  IAM Roles   │                  │
│  │              │         │              │                  │
│  │  ┌────────┐  │         │  ┌────────┐  │                  │
│  │  │  SG    │  │         │  │EC2 Role│  │                  │
│  │  │22,27017│  │         │  │  SSM   │  │                  │
│  │  └────────┘  │         │  └────────┘  │                  │
│  └──────────────┘         └──────────────┘                  │
│         │                        │                          │
│         │                        │                          │
│  ┌──────┴──────┐          ┌──────┴──────┐                   │
│  │ EC2 Instance│          │ EC2 Instance│                   │
│  │ Production  │          │  Staging    │                   │
│  └──────┬──────┘          └──────┬──────┘                   │
│         │                        │                          │
│  ┌──────┴──────┐          ┌──────┴──────┐                   │
│  │ EBS Volume  │          │ EBS Volume  │                   │
│  │   20GB      │          │   20GB      │                   │
│  │   gp3       │          │   gp3       │                   │
│  └──────┬──────┘          └─────────────┘                   │
│         │                                                   │
│  ┌──────┴──────┐                                            │
│  │  Snapshot   │                                            │
│  │   (S3)      │                                            │
│  └─────────────┘                                            │
│                                                             │
└─────────────────────────────────────────────────────────────┘

Security & Access Control

┌─────────────────────────────────────────────────────────────┐
│                   Security Layers                           │
│                                                             │
│  1. AWS IAM                                                 │
│     ├─ User/Role with EC2/EBS/SSM permissions               │
│     └─ EC2 Instance Profile with SSM access                 │
│                                                             │
│  2. Security Groups                                         │
│     ├─ SSH: 22 (restricted IPs)                             │
│     └─ MongoDB: 27017 (VPC only recommended)                │
│                                                             │
│  3. EBS Encryption                                          │
│     ├─ Volumes encrypted at rest                            │
│     └─ Snapshots encrypted                                  │
│                                                             │
│  4. SSM Session Manager                                     │
│     ├─ No SSH keys needed                                   │
│     └─ CloudTrail logging                                   │
│                                                             │
│  5. Data Anonymization                                      │
│     ├─ PII data masked                                      │
│     └─ Hash-based transformation                            │
│                                                             │
└─────────────────────────────────────────────────────────────┘

Cost Breakdown

┌──────────────────────────────────────────────────────────┐
│                   Monthly Costs                          │
├──────────────────────────────────────────────────────────┤
│                                                          │
│  Production Environment:                                 │
│    • EC2 t3.large:           $60.00                      │
│    • EBS Root 8GB gp3:       $0.64                       │
│    • EBS Data 20GB gp3:      $1.60                       │
│    • Data Transfer:          $0.00 (same region)         │
│    ─────────────────────────────────                     │
│    Subtotal:                 $62.24                      │
│                                                          │
│  Staging Environment:                                    │
│    • EC2 t3.large:           $60.00                      │
│    • EBS Root 8GB gp3:       $0.64                       │
│    • EBS Data 20GB gp3:      $1.60                       │
│    • Data Transfer:          $0.00                       │
│    ─────────────────────────────────                     │
│    Subtotal:                 $62.24                      │
│                                                          │
│  Snapshots (per snapshot):                               │
│    • 20GB snapshot:          $1.00                       │
│      (keep 1-2 for backup)                               │
│                                                          │
│  ═════════════════════════════════                       │
│  Total (both environments):  ~$125/month                 │
│                                                          │
└──────────────────────────────────────────────────────────┘