HypLab

AWS Deployment

Deploy HypLab to AWS using EKS, ECS, or EC2.

AWS Deployment

This guide covers deploying HypLab to AWS using EKS (Kubernetes), ECS (containers), or EC2 (virtual machines).

Prerequisites

  • AWS account
  • AWS CLI configured
  • kubectl (for EKS)
  • Docker
  • Domain name

Option 1: AWS EKS (Kubernetes)

Step 1: Create EKS Cluster

# Install eksctl
curl --silent --location "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp
sudo mv /tmp/eksctl /usr/local/bin

# Create cluster
eksctl create cluster \
  --name hyplab-cluster \
  --region us-east-1 \
  --nodegroup-name standard-workers \
  --node-type t3.medium \
  --nodes 3 \
  --nodes-min 2 \
  --nodes-max 5 \
  --managed

Step 2: Configure kubectl

aws eks update-kubeconfig --name hyplab-cluster --region us-east-1

Step 3: Deploy HypLab

Follow the Kubernetes Deployment Guide using your EKS cluster.

Step 4: Configure AWS Services

MongoDB Atlas on AWS

  1. Create MongoDB Atlas account
  2. Deploy cluster in AWS region (e.g., us-east-1)
  3. Configure VPC peering (optional)
  4. Get connection string

ElastiCache (Redis)

# Create Redis cluster
aws elasticache create-cache-cluster \
  --cache-cluster-id hyplab-redis \
  --cache-node-type cache.t3.micro \
  --engine redis \
  --num-cache-nodes 1 \
  --region us-east-1

Get endpoint:

aws elasticache describe-cache-clusters \
  --cache-cluster-id hyplab-redis \
  --show-cache-node-info \
  --region us-east-1

Step 5: Load Balancer

EKS automatically creates a Network Load Balancer for the ingress controller.

Get LoadBalancer address:

kubectl get ingress hyplab-ingress -n hyplab

Option 2: AWS ECS (Fargate)

Step 1: Create ECR Repositories

# Create repositories
aws ecr create-repository --repository-name api --region us-east-1
aws ecr create-repository --repository-name app --region us-east-1

# Get login token
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin <account-id>.dkr.ecr.us-east-1.amazonaws.com

Step 2: Build and Push Images

# Build and tag
docker build -t api:latest -f api/Dockerfile.prod api/
docker tag api:latest <account-id>.dkr.ecr.us-east-1.amazonaws.com/api:latest

# Push
docker push <account-id>.dkr.ecr.us-east-1.amazonaws.com/api:latest

# Repeat for web
docker build -t app:latest -f app/Dockerfile.prod app/
docker tag app:latest <account-id>.dkr.ecr.us-east-1.amazonaws.com/app:latest
docker push <account-id>.dkr.ecr.us-east-1.amazonaws.com/app:latest

Step 3: Create Task Definitions

Create ecs/gateway-task-definition.json:

{
  "family": "api",
  "networkMode": "awsvpc",
  "requiresCompatibilities": ["FARGATE"],
  "cpu": "1024",
  "memory": "2048",
  "containerDefinitions": [
    {
      "name": "gateway",
      "image": "<account-id>.dkr.ecr.us-east-1.amazonaws.com/api:latest",
      "portMappings": [
        {
          "containerPort": 4096,
          "protocol": "tcp"
        }
      ],
      "environment": [
        {
          "name": "NODE_ENV",
          "value": "production"
        },
        {
          "name": "PORT",
          "value": "4096"
        }
      ],
      "secrets": [
        {
          "name": "MONGODB_URL",
          "valueFrom": "arn:aws:secretsmanager:us-east-1:<account-id>:secret:hyplab/mongodb-url"
        },
        {
          "name": "REDIS_URL",
          "valueFrom": "arn:aws:secretsmanager:us-east-1:<account-id>:secret:hyplab/redis-url"
        }
      ],
      "logConfiguration": {
        "logDriver": "awslogs",
        "options": {
          "awslogs-group": "/ecs/api",
          "awslogs-region": "us-east-1",
          "awslogs-stream-prefix": "ecs"
        }
      },
      "healthCheck": {
        "command": ["CMD-SHELL", "curl -f http://localhost:4096/health || exit 1"],
        "interval": 30,
        "timeout": 5,
        "retries": 3
      }
    }
  ]
}

Register task definition:

aws ecs register-task-definition --cli-input-json file://ecs/gateway-task-definition.json

Step 4: Create ECS Service

# Create cluster
aws ecs create-cluster --cluster-name hyplab-cluster

# Create service
aws ecs create-service \
  --cluster hyplab-cluster \
  --service-name api \
  --task-definition api \
  --desired-count 3 \
  --launch-type FARGATE \
  --network-configuration "awsvpcConfiguration={subnets=[subnet-xxx,subnet-yyy],securityGroups=[sg-xxx],assignPublicIp=ENABLED}" \
  --load-balancers "targetGroupArn=arn:aws:elasticloadbalancing:us-east-1:<account-id>:targetgroup/api-tg/xxx,containerName=gateway,containerPort=4096"

Step 5: Application Load Balancer

# Create target group
aws elbv2 create-target-group \
  --name api-tg \
  --protocol HTTP \
  --port 80 \
  --vpc-id vpc-xxx \
  --target-type ip \
  --health-check-path /health

# Create load balancer
aws elbv2 create-load-balancer \
  --name hyplab-alb \
  --subnets subnet-xxx subnet-yyy \
  --security-groups sg-xxx

# Create listener
aws elbv2 create-listener \
  --load-balancer-arn <alb-arn> \
  --protocol HTTPS \
  --port 443 \
  --certificates CertificateArn=<cert-arn> \
  --default-actions Type=forward,TargetGroupArn=<tg-arn>

Option 3: EC2 (Virtual Machines)

Step 1: Launch EC2 Instances

# Create security group
aws ec2 create-security-group \
  --group-name hyplab-sg \
  --description "HypLab security group"

# Allow HTTP/HTTPS
aws ec2 authorize-security-group-ingress \
  --group-id sg-xxx \
  --protocol tcp \
  --port 80 \
  --cidr 0.0.0.0/0

aws ec2 authorize-security-group-ingress \
  --group-id sg-xxx \
  --protocol tcp \
  --port 443 \
  --cidr 0.0.0.0/0

# Launch instance
aws ec2 run-instances \
  --image-id ami-xxx \
  --instance-type t3.medium \
  --key-name your-key-pair \
  --security-group-ids sg-xxx \
  --subnet-id subnet-xxx \
  --user-data file://ec2/user-data.sh

Step 2: Install Docker on EC2

Create ec2/user-data.sh:

#!/bin/bash
yum update -y
yum install -y docker
systemctl start docker
systemctl enable docker
usermod -a -G docker ec2-user

# Install Docker Compose
curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose

Step 3: Deploy with Docker Compose

SSH into instance and follow Docker Production Deployment.

AWS Services Configuration

Secrets Manager

Store secrets in AWS Secrets Manager:

# Create secrets
aws secretsmanager create-secret \
  --name hyplab/mongodb-url \
  --secret-string "mongodb+srv://user:password@cluster.mongodb.net/hyplab"

aws secretsmanager create-secret \
  --name hyplab/redis-url \
  --secret-string "redis://user:password@redis-host:6379"

aws secretsmanager create-secret \
  --name hyplab/jwt-secret \
  --secret-string "your-jwt-secret"

CloudWatch Logs

ECS automatically sends logs to CloudWatch. For EC2:

# Install CloudWatch agent
wget https://s3.amazonaws.com/amazoncloudwatch-agent/amazon_linux/amd64/latest/amazon-cloudwatch-agent.rpm
sudo rpm -U ./amazon-cloudwatch-agent.rpm

Route 53 DNS

# Create hosted zone
aws route53 create-hosted-zone --name yourdomain.com --caller-reference $(date +%s)

# Create A record
aws route53 change-resource-record-sets \
  --hosted-zone-id <zone-id> \
  --change-batch file://route53/record.json

Monitoring

CloudWatch Dashboards

Create CloudWatch dashboard for:

  • API request count
  • Response times
  • Error rates
  • Container CPU/memory usage

CloudWatch Alarms

aws cloudwatch put-metric-alarm \
  --alarm-name hyplab-high-error-rate \
  --alarm-description "Alert when error rate exceeds 5%" \
  --metric-name ErrorRate \
  --namespace HypLab \
  --statistic Average \
  --period 300 \
  --threshold 5 \
  --comparison-operator GreaterThanThreshold

Cost Optimization

Use Spot Instances (EKS)

eksctl create nodegroup \
  --cluster hyplab-cluster \
  --name spot-workers \
  --instance-types t3.medium,t3.large \
  --spot \
  --nodes 2 \
  --nodes-min 1 \
  --nodes-max 5

Reserved Instances (EC2)

Purchase Reserved Instances for predictable workloads to save up to 75%.

Auto Scaling

Configure auto-scaling to scale down during low usage periods.

Backup

EBS Snapshots (EC2)

# Create snapshot
aws ec2 create-snapshot \
  --volume-id vol-xxx \
  --description "HypLab backup $(date +%Y-%m-%d)"

S3 Backups

Store MongoDB and Redis backups in S3:

# Create S3 bucket
aws s3 mb s3://hyplab-backups

# Upload backup
aws s3 cp backup.tar.gz s3://hyplab-backups/

Next Steps

On this page