AWS Deployment Guide for Student Management Portal - jameelappsintegra/student-management-portal GitHub Wiki

AWS Deployment Guide for Student Management Portal

This comprehensive guide will walk you through deploying the Student Management Portal on AWS for an educational institution, with MongoDB integration and region-specific configuration.

Table of Contents

  1. Prerequisites
  2. AWS Account Setup
  3. MongoDB Atlas Setup
  4. AWS Region Selection
  5. Deployment Options
  6. Environment Variables Configuration
  7. Domain and SSL Setup
  8. Monitoring and Logging
  9. Backup and Disaster Recovery
  10. Cost Optimization
  11. Educational Institution Best Practices
  12. Troubleshooting

Prerequisites

Before starting the deployment process, ensure you have:

  • The Student Management Portal codebase from your GitHub repository
  • Node.js and npm installed on your local machine
  • AWS CLI installed and configured
  • Git installed
  • Basic knowledge of AWS services
  • MongoDB Atlas account (or plan to create one)

AWS Account Setup

  1. Create an AWS Account (if you don't have one):

    • Go to AWS Console
    • Click "Create an AWS Account"
    • Follow the registration process
  2. Set up IAM Users and Permissions:

    # Install AWS CLI if not already installed
    pip install awscli
    
    # Configure AWS CLI
    aws configure
  3. Create an IAM User for Deployment:

    • Go to IAM in AWS Console
    • Create a new user with programmatic access
    • Attach policies: AmazonEC2FullAccess, AmazonS3FullAccess, AmazonRDSFullAccess, etc.
    • Save the access key and secret key

MongoDB Atlas Setup

  1. Create a MongoDB Atlas Account:

  2. Create a New Cluster:

    • Click "Build a Cluster"
    • Choose "AWS" as the cloud provider
    • Select the same region as your AWS deployment (for low latency)
    • Choose the appropriate tier (M0 is free for development)
    • Name your cluster (e.g., "student-portal-db")
  3. Configure Database Access:

    • Create a database user with a strong password
    • Add your IP address to the IP whitelist (or 0.0.0.0/0 for all IPs)
  4. Get Connection String:

    • Click "Connect" on your cluster
    • Choose "Connect your application"
    • Copy the connection string (you'll need this later)
    • Replace <password> with your database user's password

AWS Region Selection

Selecting the right AWS region is crucial for performance and compliance:

  1. Educational Institution Considerations:

    • Choose a region closest to your educational institution for lowest latency
    • Consider data residency requirements for educational data
    • Check if your region offers educational pricing
  2. Popular AWS Regions for Educational Institutions:

    • North America: us-east-1 (Virginia), us-west-2 (Oregon)
    • Europe: eu-west-1 (Ireland), eu-central-1 (Frankfurt)
    • Asia Pacific: ap-southeast-1 (Singapore), ap-northeast-1 (Tokyo)
  3. Region Selection Command:

    # Set your preferred region
    aws configure set region YOUR_PREFERRED_REGION

Deployment Options

Option 1: AWS Elastic Beanstalk

Elastic Beanstalk is the simplest way to deploy Node.js applications on AWS.

  1. Install EB CLI:

    pip install awsebcli
  2. Initialize EB Application:

    cd student-management-portal
    eb init
    
    # Follow the prompts:
    # - Select your region
    # - Create a new application
    # - Select Node.js platform
    # - Set up SSH for instance access (optional)
  3. Configure Environment Variables: Create a file named .ebextensions/env.config:

    option_settings:
      aws:elasticbeanstalk:application:environment:
        NODE_ENV: production
        MONGODB_DATABASE_URL: mongodb+srv://username:[email protected]/student_management
        POSTGRES_DATABASE_URL: postgresql://username:password@hostname:port/database
        NEXTAUTH_SECRET: your-secret-key
        NEXTAUTH_URL: https://your-eb-url.elasticbeanstalk.com
        TWILIO_ACCOUNT_SID: your-account-sid
        TWILIO_AUTH_TOKEN: your-auth-token
        TWILIO_PHONE_NUMBER: your-twilio-phone-number
  4. Create and Deploy Application:

    eb create student-portal-production --region YOUR_PREFERRED_REGION
  5. Open the Application:

    eb open

Option 2: AWS EC2

For more control over the server environment:

  1. Launch an EC2 Instance:

    • Go to EC2 in AWS Console
    • Click "Launch Instance"
    • Choose Amazon Linux 2 AMI
    • Select t2.micro (free tier) or larger as needed
    • Configure instance details (VPC, subnet, etc.)
    • Add storage (default is fine for starting)
    • Add tags (e.g., Name: student-portal-production)
    • Configure security group to allow HTTP (80), HTTPS (443), and SSH (22)
    • Launch instance and select/create a key pair
  2. Connect to Your Instance:

    ssh -i your-key.pem ec2-user@your-instance-public-dns
  3. Install Dependencies:

    # Update system
    sudo yum update -y
    
    # Install Node.js
    curl -sL https://rpm.nodesource.com/setup_16.x | sudo bash -
    sudo yum install -y nodejs
    
    # Install Git
    sudo yum install -y git
    
    # Install PM2 for process management
    sudo npm install -g pm2
    
    # Install Nginx
    sudo amazon-linux-extras install nginx1 -y
  4. Clone and Set Up Your Application:

    # Clone repository
    git clone https://github.com/jameelappsintegra/student-management-portal.git
    cd student-management-portal
    
    # Install dependencies
    npm install
    
    # Create .env file
    cat > .env << EOL
    MONGODB_DATABASE_URL=mongodb+srv://username:[email protected]/student_management
    POSTGRES_DATABASE_URL=postgresql://username:password@hostname:port/database
    NEXTAUTH_SECRET=your-secret-key
    NEXTAUTH_URL=https://your-domain.com
    TWILIO_ACCOUNT_SID=your-account-sid
    TWILIO_AUTH_TOKEN=your-auth-token
    TWILIO_PHONE_NUMBER=your-twilio-phone-number
    EOL
    
    # Build the application
    npm run build
  5. Configure PM2:

    # Start the application with PM2
    pm2 start npm --name "student-portal" -- start
    
    # Make PM2 start on boot
    pm2 startup
    sudo env PATH=$PATH:/usr/bin pm2 startup amazon -u ec2-user
    pm2 save
  6. Configure Nginx:

    sudo nano /etc/nginx/conf.d/student-portal.conf

    Add the following configuration:

    server {
        listen 80;
        server_name your-domain.com www.your-domain.com;
        
        location / {
            proxy_pass http://localhost:3000;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;
        }
    }
    # Test Nginx configuration
    sudo nginx -t
    
    # Restart Nginx
    sudo systemctl restart nginx

Option 3: AWS Amplify

AWS Amplify is great for Next.js applications with continuous deployment:

  1. Install Amplify CLI:

    npm install -g @aws-amplify/cli
  2. Configure Amplify:

    amplify configure
  3. Initialize Amplify in Your Project:

    cd student-management-portal
    amplify init
  4. Add Hosting:

    amplify add hosting
  5. Deploy Your Application:

    amplify publish
  6. Connect to GitHub for CI/CD:

    • Go to AWS Amplify Console
    • Click "Connect app"
    • Choose GitHub as the repository source
    • Select your repository
    • Configure build settings:
    version: 1
    frontend:
      phases:
        preBuild:
          commands:
            - npm ci
        build:
          commands:
            - npm run build
      artifacts:
        baseDirectory: .next
        files:
          - '**/*'
      cache:
        paths:
          - node_modules/**/*
    • Add environment variables in the Amplify Console

Environment Variables Configuration

Regardless of deployment method, you'll need to configure these environment variables:

MONGODB_DATABASE_URL=mongodb+srv://username:[email protected]/student_management
POSTGRES_DATABASE_URL=postgresql://username:password@hostname:port/database
NEXTAUTH_SECRET=your-secret-key
NEXTAUTH_URL=https://your-domain.com
TWILIO_ACCOUNT_SID=your-account-sid
TWILIO_AUTH_TOKEN=your-auth-token
TWILIO_PHONE_NUMBER=your-twilio-phone-number

For AWS services, you can set these:

  • In Elastic Beanstalk: Through the EB Console or .ebextensions
  • In EC2: In the .env file
  • In Amplify: Through the Amplify Console

Domain and SSL Setup

  1. Register a Domain (if you don't have one):

    • Use Amazon Route 53 or another domain registrar
    • Choose a domain relevant to your educational institution
  2. Configure DNS:

    # Create a hosted zone in Route 53
    aws route53 create-hosted-zone --name your-domain.com --caller-reference $(date +%s)
    
    # Add DNS records based on your deployment method
  3. Set Up SSL Certificate:

    # Request a certificate through AWS Certificate Manager
    aws acm request-certificate --domain-name your-domain.com --validation-method DNS --region YOUR_PREFERRED_REGION
  4. Configure HTTPS:

    • For Elastic Beanstalk: Enable HTTPS in the EB Console
    • For EC2: Update Nginx configuration to use SSL
    • For Amplify: HTTPS is enabled by default with custom domains

Monitoring and Logging

  1. Set Up CloudWatch:

    # Create a CloudWatch dashboard
    aws cloudwatch put-dashboard --dashboard-name StudentPortalDashboard --dashboard-body file://dashboard.json
  2. Configure Alarms:

    # Create an alarm for high CPU usage
    aws cloudwatch put-metric-alarm --alarm-name HighCPUAlarm --alarm-description "Alarm when CPU exceeds 70%" --metric-name CPUUtilization --namespace AWS/EC2 --statistic Average --period 300 --threshold 70 --comparison-operator GreaterThanThreshold --dimensions Name=InstanceId,Value=YOUR_INSTANCE_ID --evaluation-periods 2 --alarm-actions arn:aws:sns:YOUR_REGION:YOUR_ACCOUNT_ID:YOUR_SNS_TOPIC
  3. Application Logging:

    • For Elastic Beanstalk: Logs are automatically sent to CloudWatch
    • For EC2: Configure CloudWatch agent
    • For Amplify: Logs are available in the Amplify Console

Backup and Disaster Recovery

  1. MongoDB Atlas Backups:

    • Enable automated backups in MongoDB Atlas
    • Configure backup schedule and retention policy
  2. Application Backups:

    # Create an S3 bucket for backups
    aws s3 mb s3://student-portal-backups --region YOUR_PREFERRED_REGION
    
    # Set up a backup script
    cat > backup.sh << EOL
    #!/bin/bash
    TIMESTAMP=$(date +%Y%m%d%H%M%S)
    tar -czf /tmp/app-backup-$TIMESTAMP.tar.gz -C /path/to/student-management-portal .
    aws s3 cp /tmp/app-backup-$TIMESTAMP.tar.gz s3://student-portal-backups/
    rm /tmp/app-backup-$TIMESTAMP.tar.gz
    EOL
    
    chmod +x backup.sh
    
    # Add to crontab
    (crontab -l 2>/dev/null; echo "0 2 * * * /path/to/backup.sh") | crontab -
  3. Disaster Recovery Plan:

    • Document recovery procedures
    • Test recovery regularly
    • Consider multi-region deployment for critical systems

Cost Optimization

  1. AWS Educate or AWS Academy:

    • Check if your educational institution qualifies for AWS Educate or AWS Academy
    • These programs offer credits and discounted pricing
  2. Resource Sizing:

    • Start with smaller instances and scale as needed
    • Use auto-scaling for variable workloads
  3. Reserved Instances:

    • Consider Reserved Instances for long-term deployments
    • Can save up to 75% compared to On-Demand pricing
  4. Cost Explorer:

    # Enable Cost Explorer
    aws ce enable-cost-explorer

Educational Institution Best Practices

  1. Data Privacy Compliance:

    • Ensure FERPA compliance (for US institutions)
    • Implement appropriate data access controls
    • Document data handling procedures
  2. User Management:

    • Set up IAM roles for different staff positions
    • Implement least privilege access
    • Regular access reviews
  3. Scalability Planning:

    • Plan for enrollment periods with higher traffic
    • Consider academic calendar in scaling decisions
    • Set up auto-scaling for predictable patterns
  4. Training and Documentation:

    • Create admin guides for IT staff
    • Document deployment and maintenance procedures
    • Provide training for system administrators

Troubleshooting

  1. Common Issues and Solutions:

    • Connection issues: Check security groups and network ACLs
    • Database connection: Verify MongoDB Atlas IP whitelist
    • Application errors: Check CloudWatch logs
  2. Support Resources:

    • AWS Support: Consider Business or Enterprise support for educational institutions
    • MongoDB Atlas Support: Available with paid clusters
    • Community forums and documentation
  3. Monitoring and Alerts:

    • Set up alerts for critical metrics
    • Configure notification channels (email, SMS)
    • Create runbooks for common issues

Conclusion

This deployment guide provides a comprehensive approach to deploying the Student Management Portal on AWS for educational institutions. By following these steps, you'll have a robust, scalable, and secure application that meets the needs of your institution.

For additional assistance or custom configurations, consider consulting with an AWS partner or solution architect specializing in educational technology deployments.

⚠️ **GitHub.com Fallback** ⚠️