Skip to content
How to build your own AI automation server with n8n on AWS: local models, remote models, and a real business pipeline
← ← Back to Thinking AI

How to build your own AI automation server with n8n on AWS: local models, remote models, and a real business pipeline


Introduction

Imagine this scenario: a client sends you an email with a quote request. Automatically, the AI extracts relevant data from the email, classifies the request, generates a draft quote based on a template, sends it to the manager on Slack for approval, and after approval, creates the invoice in the accounting system and replies to the client. All without manual intervention.

This is not science fiction — it is an automation pipeline you can build with n8n, an open-source workflow automation tool, hosted on your own AWS server, connected to both local AI models (Ollama, LM Studio) and remote models (OpenAI, Claude, Gemini).

In this article I show you how to do everything: from installing the server on AWS, to connecting the AI models, and building a real business pipeline.


What is n8n and why does it matter?

n8n in 30 seconds

n8n (pronounced "n-eight-n") is an open-source workflow automation platform — think of it as Zapier or Make.com, but with three major advantages:

  • Self-hosted — runs on your server, your data stays put
  • Open-source — free for Community Edition, no artificial limits
  • AI-native — has dedicated nodes for AI agents, embeddings, vector stores, chat models

Why self-host on AWS?

n8n also offers a cloud variant (n8n Cloud, from $20/month), but self-hosting on AWS gives you:

  • Full control over data — essential for GDPR and sensitive business data
  • Lower cost — an EC2 t3.small costs ~$15/month (t3.micro is ~$7-10 but has less RAM)
  • Flexibility — you can add any resources you need, connect internal services
  • Uptime — the server is always online, webhooks work 24/7

Part 1: Installing n8n on AWS EC2

What you need

  • An AWS account (free tier is enough to get started)
  • A domain or subdomain (e.g. automation.yourdomain.com)
  • Basic terminal knowledge

Step 1: Launch an EC2 instance

  1. Log in to the AWS Console and go to EC2.

  2. Click Launch Instance and configure:

    • Name: n8n-server
    • AMI: Ubuntu 24.04 LTS
    • Instance type: t3.small (2 vCPU, 2GB RAM — minimum recommended for n8n with AI)
    • Key pair: Create or select an SSH key pair
    • Security Group: Allow ports 22 (SSH), 80 (HTTP), 443 (HTTPS)
    • Storage: 20GB SSD (gp3)
  3. Launch the instance and wait for it to start.

Step 2: Elastic IP

Allocate an Elastic IP and associate it with your instance. Without this, the public IP changes on every restart and your domain will break.

  1. EC2 → Elastic IPs → Allocate Elastic IP address
  2. Select the allocated IP → Actions → Associate Elastic IP address
  3. Select your EC2 instance

Step 3: Configure DNS

At your domain registrar, create an A record:

Type: A
Name: automation (or n8n, whatever you prefer)
Value: [Your Elastic IP]
TTL: 300

Step 4: Connect via SSH and install Docker

# SSH connection
ssh -i ~/n8n-key.pem ubuntu@YOUR_ELASTIC_IP

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

# Install Docker
sudo apt install -y docker.io docker-compose
sudo systemctl enable --now docker

# Add current user to docker group
sudo usermod -aG docker $USER
# Reconnect to apply
exit

Step 5: Install NGINX as reverse proxy

sudo apt install -y nginx

# NGINX config for n8n
sudo tee /etc/nginx/sites-available/n8n << 'EOF'
server {
    listen 80;
    server_name automation.yourdomain.com;

    location / {
        proxy_pass http://localhost:5678;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        
        # WebSocket support (essential for n8n!)
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
}
EOF

sudo ln -s /etc/nginx/sites-available/n8n /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx

Step 6: Install SSL certificate with Certbot

sudo apt install -y certbot python3-certbot-nginx
sudo certbot --nginx -d automation.yourdomain.com

Certbot configures HTTPS and HTTP redirect automatically.

Step 7: Launch n8n with Docker Compose

Create the working directory and config files:

mkdir ~/n8n && cd ~/n8n

# Generate encryption key (save it!)
ENCRYPTION_KEY=$(openssl rand -base64 24)
echo "Your key: $ENCRYPTION_KEY"

Create docker-compose.yml:

services:
  n8n:
    image: n8nio/n8n:latest
    container_name: n8n
    restart: always
    ports:
      - "127.0.0.1:5678:5678"
    environment:
      - N8N_HOST=automation.yourdomain.com
      - N8N_PORT=5678
      - N8N_PROTOCOL=https
      - NODE_ENV=production
      - WEBHOOK_URL=https://automation.yourdomain.com/
      - N8N_ENCRYPTION_KEY=YOUR_KEY_HERE
      - GENERIC_TIMEZONE=Europe/London
      - N8N_RUNNERS_ENABLED=true
    volumes:
      - n8n_data:/home/node/.n8n

volumes:
  n8n_data:

Start n8n:

docker-compose up -d

Open https://automation.yourdomain.com — you should see the n8n setup screen. Create your admin account and the installation is complete.


Part 2: Connecting AI models

This is where it gets interesting. n8n supports multiple types of AI models natively, and you can use them all in the same workflow.

Remote (cloud) models — easiest to connect

OpenAI (GPT-4, GPT-4o) — Add Credential → OpenAI API, enter API key from platform.openai.com.

Anthropic (Claude) — Add Credential → Anthropic API, enter API key from console.anthropic.com.

Google Gemini — Add Credential → Google Gemini, enter API key from Google AI Studio.

When to use remote models: complex reasoning tasks, when you need the best possible results, occasional tasks that do not justify dedicated local hardware.

Local models — zero cost per request

Option A: Ollama on the same AWS server

curl -fsSL https://ollama.ai/install.sh | sh
ollama pull qwen3:8b
ollama pull nomic-embed-text

In n8n: Add Credential → Ollama API, Base URL: http://localhost:11434.

Option B: LM Studio / Ollama on your local machine

Run OLLAMA_HOST=0.0.0.0 ollama serve locally, expose via Cloudflare Tunnel or ngrok, and use that URL in n8n. For LM Studio, start the local server and use the OpenAI API credential with your tunnel URL as Base URL.

Option C: Dedicated GPU server on AWS

Launch an EC2 with GPU (e.g. g4dn.xlarge), install Ollama or vLLM, allow access only from the n8n server IP.

When to use local models: sensitive data, high volume (zero cost per token), repetitive tasks (classification, entity extraction, short summaries).

Hybrid strategy

| Task | Model | Why | |------|-------|-----| | Email classification | Ollama (Qwen3-8B local) | High volume, simple task, zero cost | | Draft quote generation | Claude/GPT-4 (remote) | Maximum quality for client-facing output | | PDF data extraction | Ollama (Qwen3-8B local) | Sensitive data, must not go to cloud | | Report summarisation | Ollama (Qwen3-14B local) | High volume, cost-effective | | Response email generation | Claude (remote) | Tone and quality matter |


Part 3: A real business pipeline — Automated quote request processing

Scenario: your company receives quote requests by email. You want the process from receipt to sending the quote to be as automated as possible.

Workflow architecture

[Email received] 
    → [AI: Classify — is it a quote request?]
    → [AI: Extract data (client, services, budget)]
    → [Lookup client in CRM]
    → [AI: Generate draft quote]
    → [Slack notification for approval]
    → [On approval: Send email to client]
    → [Create task in project management]
    → [Log to Google Sheets]

Building it step by step in n8n

  1. Gmail Trigger — monitors inbox, filters by label/subject.
  2. AI Agent (Ollama) — classifies email into CERERE_OFERTA, INTREBARE_GENERALA, RECLAMATIE, SPAM, ALTELE.
  3. IF — routes only CERERE_OFERTA to the rest of the pipeline.
  4. AI Agent (Ollama) — extracts JSON: client name, company, services requested, budget, etc.
  5. HTTP / Airtable / Notion — lookup client in CRM.
  6. AI Agent (Claude/GPT-4) — generates professional draft quote.
  7. Slack — sends draft to #quotes channel for approval.
  8. Wait — waits for approval (webhook or Slack reaction).
  9. Gmail — sends quote to client.
  10. Post-processing — create task in Notion/Trello, add row to Google Sheets.

Result

A process that used to take 45 minutes (read email → find client → write quote → approval → send → log) is reduced to 2 minutes of review and one approval click. The rest is automatic.


Other business pipelines you can build

Once n8n is configured with AI models, possibilities are practically unlimited:

Social media monitoring: Webhook from platforms → AI classifies sentiment → Alerts on negative mentions → Generated response suggestions

Customer onboarding: Form completed → AI extracts requirements → Project plan generation → Notion space creation → Personalized welcome email

Level 1 technical support: Email/chat from customer → AI classifies problem → Knowledge base search (RAG) → Generated response → If low confidence, escalate to human

Invoice processing: Email with invoice attachment → AI extracts data from PDF → Validation → Accounting registration → Payment approval notification

Content marketing: Editorial calendar → AI generates article draft → Human review → Blog publication → Social media distribution → Engagement tracking


Production tips

Security

  • Use HTTPS (Certbot), strong n8n password, limit Security Group access.
  • Do not expose Ollama directly to the internet.
  • Store API keys in n8n Credentials, not in workflows.

Backup and persistence

# Automatic backup of n8n data (add to crontab)
0 2 * * * docker exec n8n tar czf /tmp/n8n-backup.tar.gz /home/node/.n8n \
  && docker cp n8n:/tmp/n8n-backup.tar.gz ~/backups/n8n-$(date +%Y%m%d).tar.gz

Monitoring

  • Set up a simple health check with an n8n workflow that pings itself
  • Use CloudWatch (free in AWS) to monitor CPU/RAM of the instance
  • Configure alerts if the instance stops

| Component | Monthly cost | |-----------|-------------:| | EC2 t3.small (n8n) | ~$15/month (t3.micro is ~$7-10 but has less RAM) | | Elastic IP | $0 (free when attached) | | Domain | ~$1 (amortized per month) | | OpenAI API (moderate usage) | $5-20 | | Claude API (moderate usage) | $5-15 | | Total | $25-50/month |

Compare with: a part-time employee doing the same work manually = several thousand euros/month. ROI is obvious.


Conclusion

n8n on AWS with hybrid AI models (local + remote) is probably the best cost/value ratio you can get for business process automation in 2026. Full control over data, predictable costs, and the flexibility to combine free local models with powerful remote ones — each used where it makes the most sense.

The initial setup takes a few hours. The first workflow takes about an hour to build. And from there, each new pipeline adds time saved every day.


This article is part of the technical publication series on the TEN INVENT blog. If you need help implementing AI automation in your company, contact us.