How to Self-Host n8n on AWS EC2 with Docker (Step-by-Step)?



This content originally appeared on DEV Community and was authored by Snehasish Konger

I recently published a detailed guide on my blog about setting up n8n on an AWS EC2 instance. If you’ve ever wanted to run your own automation server—without relying on third-party SaaS—this is one of the most flexible and cost-effective ways to do it.

👉 Here’s the full article on my blog: Self-Hosting n8n on AWS EC2 with Docker

But let me give you a quick breakdown here.

Why EC2 for n8n?

EC2 is Amazon’s go-to compute service. You get:

  • Full control over the instance (OS, storage, network).
  • Flexibility to scale up or down depending on workload.
  • Integration with other AWS services if you want to expand later.

And since n8n runs well in Docker, EC2 is a natural fit.

The Deployment Flow (Short Version)

Here’s the 10,000-foot view of how the process works:

  1. Launch an EC2 instance
    Start with Ubuntu 22.04 LTS. Even a t3.micro works for testing.

  2. Configure security groups
    Open inbound ports: 22 (SSH), 80, and 443 (HTTP/HTTPS). If you’re testing without SSL, you can expose port 5678 directly, but it’s not secure.

  3. Install Docker & Docker Compose

   sudo apt update && sudo apt upgrade -y
   sudo apt install docker.io docker-compose -y
  1. Set up n8n with Docker Compose
    Create a simple docker-compose.yml file mapping port 5678 (or use a reverse proxy like Nginx/Caddy for SSL).

  2. Secure with HTTPS
    Point a domain to your EC2 Elastic IP, then use Let’s Encrypt (Certbot) or Caddy to generate certificates automatically.

  3. Configure environment variables
    For example:

   N8N_HOST=n8n.example.com
   N8N_PROTOCOL=https
   WEBHOOK_URL=https://n8n.example.com/
   N8N_ENCRYPTION_KEY=$(openssl rand -base64 24)

Restart Docker Compose after editing.

Common Pitfalls

From my own setup and feedback from others, here are the usual snags:

  • Browser says site is unsafe → That’s because there’s no SSL. Add HTTPS with Let’s Encrypt or Caddy.
  • Container keeps restarting → Check your .env file for missing keys like N8N_ENCRYPTION_KEY.
  • Can’t SSH into EC2 → Use the correct username (ubuntu@ for Ubuntu), ensure your key pair is added, and security group allows port 22.
  • Workflows disappear after reboot → Mount a Docker volume or connect n8n to PostgreSQL instead of relying on SQLite.

Want the Full Walkthrough?

This is just the short version. I’ve written the full step-by-step tutorial with detailed commands, screenshots, and a troubleshooting section on my blog. You can check it out here:

👉 Self-Hosting n8n on AWS EC2 with Docker

✍ If you try this setup, let me know how it goes—or share what other cloud providers you’ve deployed n8n on.


This content originally appeared on DEV Community and was authored by Snehasish Konger