EC2 Deployment

Deploy Cognee on Amazon EC2 for traditional cloud server deployments with full control over the infrastructure and custom configurations.
EC2 deployment is ideal for organizations that need direct server access, custom networking, or integration with existing AWS infrastructure.

Why EC2?

Full Control

Complete control over server configuration, networking, and security

AWS Integration

Native integration with AWS services like RDS, S3, and VPC

Cost Predictable

Fixed costs with reserved instances and predictable billing

Custom Networking

Advanced networking configurations and security groups

Prerequisites

1

AWS Account

  • Active AWS account with EC2 permissions
  • AWS CLI installed and configured
  • Key pair created for SSH access
2

Network Setup

  • VPC with public/private subnets
  • Security groups configured for HTTP/HTTPS traffic
  • Internet Gateway for public access
3

Domain & SSL

  • Domain name (optional but recommended)
  • SSL certificate (Let’s Encrypt or AWS Certificate Manager)

Instance Configuration

Small Scale Setup
  • Instance Type: t3.medium (2 vCPU, 4GB RAM)
  • Storage: 20GB GP3 SSD
  • OS: Ubuntu 22.04 LTS
  • Databases: Local SQLite, embedded vector DB

Quick Deployment

1

Launch EC2 Instance

# Using AWS CLI
aws ec2 run-instances \
  --image-id ami-0c02fb55956c7d316 \
  --instance-type t3.medium \
  --key-name your-key-pair \
  --security-group-ids sg-12345678 \
  --subnet-id subnet-12345678 \
  --block-device-mappings '[{
    "DeviceName": "/dev/sda1",
    "Ebs": {
      "VolumeSize": 20,
      "VolumeType": "gp3"
    }
  }]' \
  --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=cognee-server}]'
Replace the AMI ID, security group, and subnet with your specific values.
2

Connect to Instance

# Get instance public IP
aws ec2 describe-instances --filters "Name=tag:Name,Values=cognee-server" \
  --query 'Reservations[*].Instances[*].PublicIpAddress'

# SSH into the instance
ssh -i /path/to/your-key.pem ubuntu@YOUR-INSTANCE-IP
3

Install Dependencies

# Update system
sudo apt update && sudo apt upgrade -y

# Install Python and pip
sudo apt install python3 python3-pip python3-venv git curl -y

# Install uv for faster Python package management
curl -LsSf https://astral.sh/uv/install.sh | sh
source $HOME/.cargo/env
4

Deploy Cognee

# Clone repository
git clone https://github.com/topoteretes/cognee.git
cd cognee

# Run automated setup script
chmod +x deployment/setup_ubuntu_instance.sh
source deployment/setup_ubuntu_instance.sh

Manual Setup Process

Environment Setup

AWS Service Integration

RDS Integration

Managed PostgreSQL
# Connect to RDS instance
POSTGRES_URL=postgresql://user:pass@your-rds-endpoint:5432/cognee

S3 Storage

Object Storage
# Configure S3 for file storage
AWS_S3_BUCKET=your-cognee-bucket
AWS_ACCESS_KEY_ID=your-access-key
AWS_SECRET_ACCESS_KEY=your-secret-key

Security Configuration

1

Security Groups

# Create security group
aws ec2 create-security-group \
  --group-name cognee-sg \
  --description "Security group for Cognee server"

# Allow SSH (port 22)
aws ec2 authorize-security-group-ingress \
  --group-id sg-12345678 \
  --protocol tcp \
  --port 22 \
  --cidr 0.0.0.0/0

# Allow HTTP/HTTPS (ports 80/443)
aws ec2 authorize-security-group-ingress \
  --group-id sg-12345678 \
  --protocol tcp \
  --port 80 \
  --cidr 0.0.0.0/0
2

SSL/TLS Setup

# Install Nginx
sudo apt install nginx certbot python3-certbot-nginx -y

# Configure Nginx reverse proxy
sudo tee /etc/nginx/sites-available/cognee << EOF
server {
    listen 80;
    server_name your-domain.com;
    
    location / {
        proxy_pass http://localhost:8000;
        proxy_set_header Host \$host;
        proxy_set_header X-Real-IP \$remote_addr;
    }
}
EOF

# Enable site and get SSL certificate
sudo ln -s /etc/nginx/sites-available/cognee /etc/nginx/sites-enabled/
sudo certbot --nginx -d your-domain.com
3

Firewall Configuration

# Configure UFW firewall
sudo ufw allow OpenSSH
sudo ufw allow 'Nginx Full'
sudo ufw --force enable

Monitoring & Maintenance

# Install monitoring tools
sudo apt install htop iotop nethogs -y

# Check system resources
htop
df -h
free -m

# Monitor Cognee service
sudo systemctl status cognee
sudo journalctl -u cognee -f

Scaling & Performance

Troubleshooting

Service Won’t Start
# Check service status
sudo systemctl status cognee
sudo journalctl -u cognee --no-pager

# Check port availability
sudo netstat -tlnp | grep :8000

# Verify environment variables
cat .env

Cost Optimization

Reserved Instances

Save up to 75%Purchase reserved instances for predictable workloads to reduce costs significantly.

Spot Instances

Development/TestingUse spot instances for non-critical workloads to save up to 90% on compute costs.
Use AWS Cost Explorer to monitor your EC2 spending and optimize instance types based on actual usage patterns.

Next Steps

High Availability

Multi-AZ SetupDeploy across multiple availability zones for improved resilience.

Monitoring Stack

CloudWatch IntegrationSet up comprehensive monitoring with CloudWatch and custom metrics.

Need Help?

Join our community for EC2 deployment support and AWS best practices.