According to Synergy Research Group, AWS held 31% of the cloud infrastructure market share as of Q1 2023, making it the most widely adopted cloud platform for deploying automation tools. If you want to self-host n8n, the open-source workflow automation platform, on your own virtual server, Amazon EC2 offers the most beginner-friendly path. Many teams switch from Zapier or Make to n8n to cut costs, avoid per-execution pricing, and gain full control over their data. However, beginners often struggle with server setup, Docker configuration, security groups, and SSL certificates. This step by step guide to host n8n on AWS EC2 for beginners removes the guesswork. You will learn how to launch an EC2 instance, install Docker, deploy n8n in a container, configure a reverse proxy with Nginx, and secure everything with SSL. By the end, you will have a production-ready n8n instance accessible via your own domain name.
Quick Answer: To host n8n on AWS EC2, launch a t3.medium Ubuntu instance, open ports 80 and 443, install Docker and Docker Compose, create a docker-compose.yml with n8n image and a PostgreSQL database, deploy with docker-compose up -d, then point your domain to the instance's public IP and configure Nginx with Let's Encrypt SSL.
Why Host n8n on AWS EC2?
Full Data Control and Privacy
n8n is an open-source workflow automation tool that lets you connect APIs, databases, and web services without per-execution charges. When you self-host on AWS EC2, your workflow data never passes through a third-party SaaS provider. Amazon EC2, launched on August 25, 2006, allows users to rent virtual computers and run their own applications with full root access. You control exactly where your data lives, what firewall rules apply, and how backups are handled. For companies handling sensitive customer data, this self-hosted approach satisfies GDPR and SOC 2 requirements more easily than relying on a cloud-hosted automation platform.
Significant Cost Savings at Scale
n8n's cloud plan starts at $20 per month for 5 active workflows, while Zapier's premium tiers exceed $100 monthly for high-volume tasks. A t3.medium EC2 instance in the US-East region costs approximately $30 per month and can run dozens of active workflows with thousands of executions. Amazon EC2 uses a pay-as-you-go model — you pay by the second for active servers. For example, a marketing agency running 30 automated workflows for 10 clients would pay $200+ on Zapier but under $35 on an EC2-hosted n8n instance. Reserved instances and Savings Plans can reduce that cost by up to 72% for predictable workloads.
Scalability and Integration with AWS Services
EC2 instances scale vertically by stopping the instance and changing the instance type. If your n8n workflows outgrow a t3.medium, you can upgrade to a t3.large or m5.large in minutes. AWS also offers Elastic Block Store (EBS), added on August 20, 2008, for persistent storage that survives instance restarts. You can integrate n8n with other AWS services like S3 for file storage, RDS for managed databases, and SES for email automation. This ecosystem advantage makes AWS a strategic choice over smaller VPS providers like DigitalOcean or Linode.
Step by Step Guide: Launching Your EC2 Instance
Step 1 — Create an AWS Account and Choose an Instance Type
Go to aws.amazon.com and create an account. Navigate to the EC2 dashboard under the Services menu. Click "Launch Instance" and select the Ubuntu Server 24.04 LTS AMI. For n8n with PostgreSQL, choose a t3.medium instance (2 vCPUs, 4 GB RAM) to handle moderate workflow volumes. The t2.micro free-tier instance works for testing but often runs out of memory when processing large payloads. Name your instance "n8n-prod" and tag it with Environment=Production for easy identification.
- Open the AWS Management Console and search for "EC2"
- Click "Launch Instance" in the top-right corner
- Name your instance (e.g., n8n-prod-us-east-1)
- Select "Ubuntu Server 24.04 LTS 64-bit (x86)" as the AMI
- Choose "t3.medium" as the instance type
- Create or select an existing key pair (PEM format) and download it securely
Step 2 — Configure Security Groups
Security groups act as virtual firewalls for your EC2 instance. You must open specific ports for n8n to function and be accessible. By default, AWS allows outbound traffic but restricts inbound traffic. Create a security group named "n8n-sg" with the following rules:
- SSH (Port 22) — restrict to your IP address only
- HTTP (Port 80) — allow from anywhere (0.0.0.0/0) for Let's Encrypt challenges
- HTTPS (Port 443) — allow from anywhere for secure web access
- n8n default (Port 5678) — restrict to your IP for direct troubleshooting, or omit entirely if using Nginx
Example: A team in New York would set the SSH rule to allow inbound traffic only from their office IP (e.g., 203.0.113.50/32), preventing unauthorized access attempts that AWS detected over 400 million times in 2022 alone.
Step 3 — Connect to Your Instance
After the instance launches, note the public IPv4 address from the instance details page. Connect via SSH from your terminal using the downloaded key pair.
- Open Terminal (macOS/Linux) or PowerShell (Windows)
- Navigate to the directory containing your .pem key file
- Run:
chmod 400 your-key.pemto set correct permissions - Run:
ssh -i your-key.pem ubuntu@your-public-ipv4-address - Type "yes" when prompted to accept the host fingerprint
If you see the Ubuntu welcome banner, you are connected successfully. Alternatively, use the AWS EC2 Instance Connect browser-based SSH client from the console.
Installing Docker and Deploying n8n with Docker Compose
Step 4 — Install Docker Engine and Docker Compose
Docker, first released in March 2013, automates the deployment of applications within lightweight containers. Using Docker to run n8n ensures consistent behavior, easy updates, and clean dependency management. On your EC2 instance, run the following commands to install Docker and Docker Compose.
sudo apt update && sudo apt upgrade -y— refresh package lists and upgrade softwarecurl -fsSL https://get.docker.com -o get-docker.sh— download the official Docker installation scriptsudo sh get-docker.sh— install Docker Engine, CLI, and containerdsudo usermod -aG docker ubuntu— add the ubuntu user to the docker group- Log out and reconnect via SSH so the group change takes effect
sudo apt install docker-compose-plugin -y— install Docker Compose plugin
Verify the installation by running docker --version and docker compose version. You should see Docker 24.x or newer and Compose v2.x or newer.
Step 5 — Create the Docker Compose File for n8n
Create a project directory and a docker-compose.yml file that defines n8n and a PostgreSQL database. PostgreSQL is recommended over SQLite for production environments because it handles concurrent workflow executions and large data volumes more reliably. Create the file by running mkdir ~/n8n && cd ~/n8n && nano docker-compose.yml and paste the following configuration:
- Service name "n8n" using the image
n8nio/n8n:latest - Port mapping: 5678:5678
- Environment variables:
N8N_HOST,N8N_PORT=5678,N8N_PROTOCOL=https,WEBHOOK_URL, database credentials - Volume mount for persistent workflows:
~/.n8n:/home/node/.n8n - PostgreSQL service named "postgres" using image
postgres:16-alpinewith a named volume for data - Depends-on directive ensuring postgres starts before n8n
Example: A SaaS company connecting Stripe webhooks to Slack notifications would configure WEBHOOK_URL=https://n8n.mycompany.com/ so incoming webhook triggers resolve to the correct domain.
Step 6 — Start n8n with Docker Compose
From the ~/n8n directory, run docker compose up -d to start both containers in detached mode. Wait 30-60 seconds for n8n to complete its initial setup. Verify both containers are running with docker ps — you should see "n8nio/n8n" and "postgres" listed with "Up" status. Access n8n directly by navigating to http://your-public-ipv4:5678 in your browser. You will see the n8n setup wizard prompting you to create an admin account. Do not skip this step — the first registered user becomes the instance owner.
Securing n8n with Nginx Reverse Proxy and SSL
Step 7 — Install and Configure Nginx
A reverse proxy sits between the internet and your application server, forwarding client requests and providing TLS encryption. Nginx is the most popular open-source reverse proxy for this purpose. Install it by running sudo apt install nginx -y. Create a server block configuration file at /etc/nginx/sites-available/n8n that listens on port 80, sets the server_name to your domain, and proxies requests to http://127.0.0.1:5678. Create a symlink to /etc/nginx/sites-enabled/ and reload Nginx with sudo nginx -t && sudo systemctl reload nginx. Point your domain's DNS A record to the EC2 instance's public IPv4 address from your domain registrar's DNS panel.
Step 8 — Install Let's Encrypt SSL Certificate
HTTPS encryption is mandatory for n8n webhooks, as many third-party services (Stripe, GitHub, Slack) reject non-HTTPS webhook URLs. Let's Encrypt provides free SSL certificates valid for 90 days with automatic renewal. Install Certbot by running sudo apt install certbot python3-certbot-nginx -y. Generate the certificate by running sudo certbot --nginx -d n8n.yourdomain.com -d www.n8n.yourdomain.com. Certbot automatically modifies your Nginx configuration to handle HTTPS on port 443 and sets up a cron job for renewal. Example: A fintech startup routing Plaid bank verification webhooks through n8n would fail compliance checks without valid SSL — Let's Encrypt resolves this at zero cost.
n8n Self-Hosting: EC2 vs Other Deployment Options
Choosing the right hosting platform depends on your budget, technical comfort level, and scalability requirements. Below is a comparison of the most common deployment environments for n8n.
| Platform | Monthly Cost (Entry) | Best For |
|---|---|---|
| AWS EC2 (t3.medium) | ~$30.37 | Production workloads needing AWS ecosystem integration |
| DigitalOcean Droplet (2 GB) | ~$12.00 | Simple deployments with predictable flat pricing |
| Hetzner Cloud (CX22) | ~$5.50 | Budget-conscious teams in Europe |
| n8n Cloud (Starter) | ~$20.00 | Non-technical users wanting zero maintenance |
| Local Docker (self-managed) | $0.00 (hardware costs apply) | Development and testing only |
Common Mistakes When Hosting n8n on AWS EC2
Mistake 1: Using the Free Tier t2.micro Instance
The t2.micro offers only 1 GB of RAM, which is insufficient for n8n running alongside PostgreSQL. The n8n container alone can consume 500-800 MB during heavy workflow executions. When memory runs out, the Linux OOM killer terminates the n8n process, causing silent failures. Fix: Upgrade to a t3.medium (4 GB RAM) or t3.small (2 GB RAM with swap space configured). Monitor memory usage with docker stats and the free -h command.
Mistake 2: Leaving Port 5678 Open to the Public
Exposing n8n's default port 5678 directly to the internet bypasses your Nginx SSL termination and authentication layer. Attackers can access the n8n setup wizard if no admin account exists, seizing control of your instance. Fix: Remove the port 5678 rule from your security group after Nginx is configured. Only allow access via HTTPS on port 443 through the reverse proxy.
Mistake 3: Not Configuring Persistent Volumes
Without named volumes for PostgreSQL data and the n8n storage directory, all workflow definitions and execution history are lost when you restart or update the container. Fix: Define named volumes in your docker-compose.yml (e.g., n8n_data and pg_data) and mount them to the correct container paths.
Mistake 4: Forgetting to Set the WEBHOOK_URL Environment Variable
n8n uses WEBHOOK_URL to generate correct callback URLs for webhook trigger nodes. If this variable points to localhost or HTTP instead of your HTTPS domain, webhook-based workflows fail silently. Fix: Set WEBHOOK_URL=https://n8n.yourdomain.com/ in the environment section of your docker-compose.yml file, then recreate the containers with docker compose up -d --force-recreate.
Mistake 5: Ignoring Database Backups
A single EBS volume failure or accidental docker compose down -v command can wipe out months of workflow configurations and execution logs. Fix: Schedule daily PostgreSQL dumps using docker exec postgres pg_dump -U n8n n8n > backup_$(date +%F).sql via a cron job, and upload backups to an S3 bucket using the AWS CLI with lifecycle policies for 30-day retention.
Pro Tips
- Use
docker compose pull && docker compose up -dto update n8n to the latest version without losing data or configuration. - Enable
N8N_DIAGNOSTICS_ENABLED=falsein the environment section to disable anonymous telemetry and improve startup speed. - Set up an Application Load Balancer (ALB) with health checks targeting /healthz if you plan to run multiple n8n instances behind a single endpoint.
- Use AWS Systems Manager Session Manager instead of SSH for instance access — it eliminates the need for inbound SSH rules and logs all session activity to CloudTrail.
- Configure
N8N_METRICS=trueand expose Prometheus-compatible metrics to monitor workflow execution times and queue depth in Grafana.
FAQ
What is n8n and why should I self-host it on AWS EC2?
n8n is a fair-code workflow automation tool that connects 400+ integrations, including Google Sheets, Slack, AWS services, and custom HTTP APIs. Self-hosting on AWS EC2 gives you unrestricted access to the full feature set, unlimited workflow executions, and complete data sovereignty. AWS EC2 provides reliable infrastructure with 99.99% availability SLA across multiple availability zones and seamless integration with 200+ other AWS services for storage, monitoring, and networking.
How does self-hosting n8n compare to using n8n Cloud or Zapier?
Self-hosted n8n allows unlimited executions with no per-task fees, making it significantly cheaper at scale — a t3.medium EC2 instance at ~$30/month can replace a Zapier plan costing $150+/month. However, self-hosting requires you to manage infrastructure, security updates, and database backups yourself. n8n Cloud ($20+/month) handles maintenance and updates but limits active workflows and execution volume based on your tier.
What EC2 instance type should I choose for running n8n?
For production, a t3.medium (2 vCPUs, 4 GB RAM, ~$30/month) is the recommended starting point and runs n8n with PostgreSQL smoothly for moderate workflow volumes. For testing or development, a t3.small (2 vCPUs, 2 GB RAM) works if you add 2 GB of swap space. Avoid the t2.micro free-tier instance because its 1 GB RAM causes frequent out-of-memory crashes during heavy workflow executions.
Why is my n8n instance returning a 502 Bad Gateway error?
A 502 Bad Gateway error from Nginx typically means the n8n container is not running or is still starting up. Check container status with docker ps and review logs with docker logs n8n. Common causes include incorrect database credentials in the docker-compose.yml, a PostgreSQL container that has not finished initializing, or insufficient memory causing the OOM killer to terminate the n8n process. Restart both containers with docker compose restart.
How do I update n8n to the latest version on AWS EC2?
Updating n8n takes less than two minutes with Docker Compose. Navigate to your ~/n8n directory, run docker compose pull to fetch the latest n8n image, then execute docker compose up -d which recreates only the containers that have a new image. Your workflow data and settings are preserved because they are stored in named volumes. Always test updates on a staging instance first, as new n8n versions occasionally introduce breaking changes to node configurations.
Conclusion
Self-hosting n8n on AWS EC2 gives you unlimited workflow automation power at a fraction of the cost of managed platforms. This guide walked you through every step — choosing the right instance type, configuring security groups, installing Docker, deploying n8n with PostgreSQL, setting up Nginx as a reverse proxy, and securing traffic with Let's Encrypt SSL. The entire setup takes under 45 minutes for a beginner and costs approximately $30 per month for a production-ready instance. With Docker Compose, updates and maintenance require a single command, while persistent volumes ensure your data survives container restarts. Whether you are a solo developer automating personal tasks or a team building client-facing automation pipelines, this architecture scales from dozens to thousands of workflow executions per day.
- Choose a t3.medium EC2 instance with Ubuntu 24.04 LTS for reliable n8n performance and avoid the free-tier t2.micro.
- Always use Docker Compose with PostgreSQL and named volumes for data persistence and easy updates.
- Secure your instance with Nginx reverse proxy, Let's Encrypt SSL, and restricted security group rules — never expose port 5678 to the public internet.
- Schedule daily PostgreSQL backups to S3 to prevent data loss from accidental container removal or EBS failures.
Sources
- Amazon Elastic Compute Cloud — Wikipedia
- Amazon Web Services — Wikipedia
- Docker (software) — Wikipedia
- Containerization (computing) — Wikipedia
- Reverse proxy — Wikipedia
- Node.js — Wikipedia
- n8n Docker Installation — Official Documentation
- Amazon EC2 Security Groups — AWS Documentation
- Certbot Instructions — Electronic Frontier Foundation
0 comments:
Post a Comment