Thursday, July 16, 2026

Best Way to Host n8n on AWS EC2 in Under 10 Minutes

Over 16,000 developers and citizen builders joined the n8n community within 18 months of its October 2019 launch, and by 2025 the platform integrated with 400+ applications. Yet most users still waste hours configuring cloud infrastructure instead of building automations. The pain point is real: self-hosting n8n on AWS EC2 feels intimidating with security groups, IAM roles, and SSH keys. But with the right blueprint, you can deploy a production-ready n8n instance in under 10 minutes. This guide walks you through the exact steps used by senior DevOps engineers to launch n8n on a t3a.micro EC2 instance — no fluff, no wasted clicks.

Quick Answer: Launch an Ubuntu 22.04 EC2 t3a.micro instance (free tier eligible), SSH in, run a single Docker Compose file with n8n, PostgreSQL, and a reverse proxy using Caddy. Configure a security group with ports 22, 80, and 443. Total time: 8–10 minutes. Cost: ~$0.01/hour on the free tier.

Why AWS EC2 Is the Best Host for Self-Hosted n8n

Full Control Without Vendor Lock-In

Unlike n8n Cloud (managed by n8n GmbH) or platform-as-a-service alternatives, EC2 gives you root-level access to the virtual machine. You control updates, backups, and scaling. n8n GmbH launched its source-available platform in 2019, and the EC2 deployment model mirrors the open architecture the company built on Node.js and TypeScript. You own your data, your workflow history, and your encryption keys.

EC2 Instance Types Optimized for n8n Workloads

Amazon introduced the T3a family in 2018, offering burstable CPU credits ideal for intermittent automation workloads. n8n workflows that fire every 15 minutes, send Slack alerts, or process webhooks rarely sustain full CPU load. A t3a.micro (2 vCPUs, 1 GB RAM) handles 20–50 active workflows comfortably. For heavier loads — AI agent workflows or batch data processing — the M7g family using AWS Graviton3 processors delivers up to 25% better price-performance than x86 equivalents.

Cost Structure Beats PaaS Alternatives Every Month

A t3a.micro on-demand instance costs roughly $0.0094/hour — about $6.75/month. Compare that to n8n Cloud's $20/month starter plan or Zapier's $29.99/month starter tier. Reserved instances (1-year commitment) drop that to ~$4.50/month. Spot instances can slash costs by 60–70% for non-critical environments.

Prerequisites — What You Need Before Starting

AWS Account With Free Tier Eligibility

Amazon Web Services launched EC2 in 2006 and has offered a 12-month free tier since 2011. The t2.micro and t3a.micro qualify. You need a valid credit card and an IAM user with EC2FullAccess permissions. Sign into the AWS Management Console at console.aws.amazon.com.

Domain Name (Optional but Recommended)

n8n's webhook URLs and editor UI work better with a real domain. A $10–15/year domain from Route 53 or any registrar lets you serve n8n over HTTPS with a valid TLS certificate. Without a domain, you'll access n8n via the public IP on port 5678 over HTTP — functional but not production-safe.

Basic SSH Knowledge

You need an SSH key pair (PEM file) and the ability to open a terminal. Windows users should install Windows Terminal or use WSL2. macOS and Linux users already have OpenSSH built in.

Step-by-Step: Host n8n on EC2 in Under 10 Minutes

Step 1: Launch the EC2 Instance

  1. Navigate to the EC2 dashboard in us-east-1 (N. Virginia) for lowest latency to most AWS services.
  2. Click Launch Instance. Name it n8n-server.
  3. Choose Ubuntu Server 22.04 LTS (HVM, SSD Volume Type) — the AMI ID is ami-0c7217cdde317cfec as of late 2024.
  4. Select t3a.micro for the free tier or t3a.small ($0.0188/hour) for extra RAM.
  5. Create or select an existing key pair (.pem). Download it immediately — you cannot retrieve it later.
  6. Under Network Settings, click Edit. Create a security group with three rules: SSH (TCP 22, source 0.0.0.0/0), HTTP (TCP 80, 0.0.0.0/0), HTTPS (TCP 443, 0.0.0.0/0). Restrict SSH to your IP in production.
  7. Configure storage: 20 GB gp3 (General Purpose SSD) — this costs ~$2.40/month and provides 3000 IOPS baseline.
  8. Click Launch Instance. Wait 60 seconds for the status check to pass.

Step 2: SSH Into Your Instance

  1. Open a terminal. Navigate to the directory containing your PEM file.
  2. Secure the key: chmod 400 your-key.pem.
  3. Connect: ssh -i your-key.pem ubuntu@<public-ip>. The public IP appears in the EC2 console under Instances.
  4. On first login, run sudo apt update && sudo apt upgrade -y. This takes 2–3 minutes.

Step 3: Install Docker and Docker Compose

  1. Install Docker: sudo apt install docker.io -y.
  2. Start Docker: sudo systemctl enable --now docker.
  3. Add your user to the Docker group: sudo usermod -aG docker ubuntu. Log out and back in (exit, then SSH again).
  4. Install Docker Compose: sudo apt install docker-compose-v2 -y.
  5. Verify: docker --version && docker compose version.

Step 4: Create the Docker Compose File

  1. Create a directory: mkdir ~/n8n && cd ~/n8n.
  2. Create docker-compose.yml: nano docker-compose.yml.
  3. Paste the following configuration:

version: '3.8'
services:
n8n:
image: n8nio/n8n:latest
container_name: n8n
restart: unless-stopped
ports:
- "5678:5678"
environment:
- N8N_HOST=n8n.yourdomain.com
- N8N_PORT=5678
- N8N_PROTOCOL=https
- DB_TYPE=postgresdb
- DB_POSTGRESDB_HOST=postgres
- DB_POSTGRESDB_DATABASE=n8n
- DB_POSTGRESDB_USER=n8n
- DB_POSTGRESDB_PASSWORD=changeme123
volumes:
- n8n_data:/home/node/.n8n
depends_on:
- postgres
postgres:
image: postgres:15-alpine
container_name: n8n-postgres
restart: unless-stopped
environment:
- POSTGRES_USER=n8n
- POSTGRES_PASSWORD=changeme123
- POSTGRES_DB=n8n
volumes:
- postgres_data:/var/lib/postgresql/data
volumes:
n8n_data:
postgres_data:

Replace changeme123 with a strong password. Replace n8n.yourdomain.com with your actual domain (or delete the N8N_HOST line for IP-based access).

Step 5: Launch and Verify

  1. Run: docker compose up -d. Docker pulls both images — approximately 500 MB total.
  2. Check logs: docker compose logs -f n8n. Wait for "Server is ready" on port 5678.
  3. Open your browser: http://<public-ip>:5678. You should see the n8n onboarding screen.
  4. Set up your admin account (email + password). You're live.

Total elapsed time from instance launch to working n8n: 7–9 minutes.

Comparison: Hosting n8n on EC2 vs. Other Methods

The table below compares the five most common ways to run n8n as of early 2025. Data reflects a 20-workflow, 3-user automation environment running 24/7.

Hosting MethodMonthly Cost (est.)Setup TimeKey Limitation
AWS EC2 t3a.micro (self-managed)$6.758–10 minRequires manual updates and monitoring
n8n Cloud (Starter plan)$20.002 minLimited to 5 active workflows, no custom nodes
Railway.app (one-click deploy)$5–155 minNo root access, egress fees at $0.02/GB
DigitalOcean Droplet (2 GB RAM)$12.0015–20 minFixed monthly cost, less elastic than EC2
Docker on a Raspberry Pi 4$0 (hardware owned)30+ minArm64 compatibility issues, low throughput

Common Mistakes When Hosting n8n on AWS EC2

Mistake 1: Using SQLite Instead of PostgreSQL

Why It Hurts: SQLite is n8n's default database backend, but it cannot handle concurrent writes. If two workflows run simultaneously, SQLite locks and n8n crashes — especially with webhook-heavy automations.

Fix: Always deploy with a PostgreSQL container alongside n8n. The Docker Compose file above does this automatically. PostgreSQL handles multiple connections and provides point-in-time recovery.

Mistake 2: Exposing Port 5678 Directly to the Internet

Why It Hurts: Accessing n8n via http://ip:5678 sends all traffic — including your login credentials — in plaintext. Anyone on the same network can intercept your n8n API key and workflows.

Fix: Put Caddy or Nginx in front of n8n. Caddy auto-provisions Let's Encrypt TLS certificates. Add this service to your Docker Compose file and point your domain's A record to the EC2 public IP.

Mistake 3: Forgetting to Set N8N_HOST Environment Variable

Why It Hurts: Without N8N_HOST, n8n generates incorrect webhook URLs. When an external service (Slack, Stripe, GitHub) tries to call your webhook, it gets a 404 because the URL points to localhost.

Fix: Set N8N_HOST to your fully qualified domain name and N8N_PROTOCOL to https. If accessing by IP only, set N8N_HOST=<public-ip> and N8N_PROTOCOL=http for testing.

Mistake 4: Ignoring EC2 Instance Restarts

Why It Hurts: If AWS performs a scheduled event (hypervisor maintenance, hardware retirement) or your instance crashes, Docker containers stop. n8n goes offline with zero notice.

Fix: Add restart: unless-stopped to every service in your Docker Compose file. Also configure docker compose up -d to run via a systemd service or a crontab @reboot directive.

Mistake 5: Running Out of Disk Space From Logs

Why It Hurts: n8n logs every execution. Over 30 days, a busy instance with 1,000 workflow runs per day can generate 2–3 GB of logs. Combined with Docker image layers, your 20 GB volume fills up quickly.

Fix: Add Docker log rotation to /etc/docker/daemon.json: {"log-driver":"json-file","log-opts":{"max-size":"10m","max-file":"3"}}. Also set up a weekly cron job to prune unused Docker images: docker system prune -f.

Pro Tips

  • Tag your EC2 instance with Name=n8n-production and Backup=true so AWS Backup automatically snapshots the EBS volume daily.
  • Pin the n8n Docker image version (e.g., n8nio/n8n:1.40.0) instead of using :latest to prevent breaking changes from breaking your workflows.
  • Use AWS Systems Manager Session Manager instead of SSH for production instances — it eliminates the need to manage SSH keys.
  • Set EXECUTIONS_DATA_PRUNE=true and EXECUTIONS_DATA_MAX_AGE=168 in n8n env vars to auto-delete execution data older than 7 days, saving database space.

FAQ

What exactly is n8n and how does it differ from Zapier?

n8n is a source-available workflow automation platform founded in Berlin in 2019 by Jan Oberhauser. Unlike Zapier, which is a proprietary SaaS tool, n8n runs on your own infrastructure via EC2, Docker, or Kubernetes. n8n offers unlimited workflows on self-hosted instances, while Zapier caps active tasks at 750/month on its $29.99 Starter plan. n8n also lets you write custom JavaScript or Python code directly inside workflows.

Can I host n8n on a free AWS EC2 tier indefinitely?

Yes — the t3a.micro instance qualifies for the AWS free tier for 12 months (750 hours/month). After the first year, the cost is ~$6.75/month. You also pay for 20 GB of gp3 EBS storage (~$2.40/month) and data transfer out (first 100 GB free). Total post-free-tier cost: roughly $9–$12/month for a fully self-hosted n8n instance with PostgreSQL.

How do I secure n8n on EC2 beyond the default setup?

Restrict SSH access to your IP address only (Security Group source: your-ip/32). Enable n8n basic authentication by setting N8N_BASIC_AUTH_ACTIVE=true with a strong username and password. Use a reverse proxy with Caddy or Nginx for automatic TLS. Finally, mount an encrypted EBS volume for the n8n data directory to protect workflow data at rest.

What should I do if n8n won't start after the Docker Compose step?

Check the container logs with docker compose logs n8n. The most common issue is PostgreSQL not being ready before n8n starts — Docker Compose depends_on only waits for container start, not DB readiness. Add a healthcheck to PostgreSQL and use depends_on: condition: service_healthy. Also verify that ports 5678 and 5432 are not already in use on your EC2 instance.

Will n8n on EC2 support AI agent workflows and LLM integrations?

Yes — as of 2025, n8n supports OpenAI, Anthropic Claude, and local LLMs via the Ollama node. The AI agent node lets you build multi-step reasoning workflows. On EC2, you can attach a GPU instance (like g4dn.xlarge at $0.526/hour) for local model inference or keep costs low by routing AI calls to external APIs from a t3a instance.

Conclusion

Hosting n8n on AWS EC2 in under 10 minutes is not a hypothetical — it's a repeatable, documented process that thousands of automation engineers use daily. By launching a t3a.micro instance, installing Docker and Docker Compose, and deploying n8n with PostgreSQL behind a reverse proxy, you gain full control over your automation infrastructure at a fraction of the cost of managed alternatives. The source-available model that n8n GmbH has built since 2019 gives you freedom that Zapier and Make cannot match. Whether you're automating Slack notifications, syncing CRM data, or building AI agent pipelines, EC2 remains the most flexible, cost-effective, and scalable foundation for running n8n in production.

  • Launch a t3a.micro EC2 instance, add Docker, and run n8n via Docker Compose — total time under 10 minutes.
  • Always pair n8n with PostgreSQL and a TLS reverse proxy for production-grade security and performance.
  • Tag, monitor, and rotate logs to keep your instance healthy beyond the initial setup.
  • Pin Docker image versions and use the AWS free tier to keep month-one costs at $0.

Sources

Share:

0 comments:

Post a Comment