Let's Deploy n8n on ec2 instances 🚀🚀🚀

Published: (December 10, 2025 at 08:05 AM EST)
4 min read
Source: Dev.to

Source: Dev.to

I really love automating

I’ve always loved automating things in my workflows. When I stumbled on n8n, I was honestly in awe. Suddenly all the ideas I had before—like updating Google Sheets, posting to social media, hosting my own APIs, syncing Google Drive to an S3 bucket, and a lot more—became realistic without needing to learn a new framework or library for every single task. n8n makes it much easier to build small automations that actually ship and help you in day‑to‑day work, and that’s what made me fall in love with it.

Below is a step‑by‑step guide to deploy n8n on an AWS EC2 instance so you can run your own automations on your own infrastructure.

1. Create an EC2 Instance

  1. Log in to the AWS Management Console and navigate to the EC2 Dashboard.

  2. Click Launch instance.

  3. Name – give your instance a recognizable name, e.g., n8n.

  4. Application and OS Images (AMI) – select Amazon Linux 2023 AMI (Free Tier eligible).

  5. Architecture – choose 64-bit (ARM) for better cost efficiency (Graviton processors).

  6. Instance type – for this tutorial use t4g.medium (2 vCPU, 4 GB RAM).

    Why t4g.medium?

    • ~40 % better price‑to‑performance than comparable x86 instances.
    • Sufficient resources for n8n with multiple workers.
    • Burstable performance with CPU credits.
    • ~40 % lower cost than t3.medium.
    • Production‑ready (unlike t4g.micro).
    InstancevCPURAMTypical Use
    t4g.micro11 GBFree Tier only, limited
    t4g.medium24 GBSmall‑to‑medium deployments (recommended)
    t4g.large28 GBHigh‑volume workflows
  7. Key pair (login) – select an existing key pair or create a new one. This is required for SSH access.

  8. Network settings – create a new security group with the following inbound rules:

    RulePortProtocolSourcePurpose
    SSH22TCPYour IP (or 0.0.0.0/0 for testing only)Remote terminal access
    HTTP80TCP0.0.0.0/0Web traffic (redirect to HTTPS)
    HTTPS443TCP0.0.0.0/0Secure web traffic for n8n UI
  9. Storage – the default 8 GiB gp3 volume is sufficient for a basic installation.

  10. Advanced details – scroll to the User data field and paste the script from the next section.

  11. Review the summary and click Launch instance.

2. User Data Script (Automatic Setup)

Paste the following script into the User data text box. It updates the system, installs Git, Docker, and Docker Compose, and configures Docker permissions.

#!/bin/bash
yum install -y git docker

# Install Docker Compose plugin (system-wide)
mkdir -p /usr/local/lib/docker/cli-plugins
curl -SL "https://github.com/docker/compose/releases/latest/download/docker-compose-linux-$(uname -m)" \
  -o /usr/local/lib/docker/cli-plugins/docker-compose
chmod +x /usr/local/lib/docker/cli-plugins/docker-compose

# Enable and start Docker
systemctl enable docker
systemctl start docker

# Allow ec2-user to run Docker without sudo
usermod -aG docker ec2-user

The script runs automatically when the instance boots, saving you several manual steps.

3. Connect to Your Instance

  1. In the EC2 console, select your running instance and click Connect.
  2. Choose the EC2 Instance Connect tab, keep the default username ec2-user, and click Connect.
  3. A browser‑based terminal will open. Verify that Docker Compose installed correctly:
docker compose --version

If a version number is displayed, the environment is ready.

4. Deploy n8n Using a Pre‑Configured Repository

git clone https://github.com/coozgan/hosting-n8n-aws.git
cd hosting-n8n-aws

This repository sets up a production‑ready n8n deployment with:

  • n8n workers – asynchronous workflow execution.
  • Redis – job queue and retry handling.
  • PostgreSQL – persistent storage for workflows, executions, and user data.
  • Caddy – reverse proxy with automatic SSL/TLS certificates.

4.1 Configure Environment Variables

cp .env-example .env
nano .env

Add (or edit) the following variables:

# Domain Configuration
DOMAIN=your-domain.com   # use localhost if you don't have a domain

# n8n Encryption (generate a strong random key)
N8N_ENCRYPTION_KEY=YOUR_STRONG_KEY

# PostgreSQL Database
POSTGRES_PASSWORD=YOUR_POSTGRES_PASSWORD

# Timezone
GENERIC_TIMEZONE=America/New_York

Optional – DuckDNS domain (for testing without a custom domain)

  1. Create a subdomain at https://www.duckdns.org.
  2. Add your instance’s public IP (obtain with curl ifconfig.me) to the DuckDNS record.
  3. Set DOMAIN in .env to the DuckDNS subdomain.

Important: Keep N8N_ENCRYPTION_KEY and POSTGRES_PASSWORD safe. Losing them means you cannot recover your workflows or data.

Save and exit (Ctrl+X, then Y and Enter).

4.2 Start the Stack

docker compose up -d

Verify that all containers are running:

docker compose ps

Stream the logs to ensure everything started correctly:

docker compose logs -f

5. Access the n8n UI

  • With a custom domain: https://your-domain.com
  • Without a domain (testing): http://

You should see the n8n login screen. Create your first user account.

Congratulations! You now have a functional n8n deployment on AWS.

6. Scaling: Adding More Workers

To add additional worker instances, edit docker-compose.yml and add entries similar to the examples below:

n8n-worker-2:
  extends: n8n-worker
  container_name: n8n-worker-2
  # ...additional configuration if needed

n8n-worker-3:
  extends: n8n-worker
  container_name: n8n-worker-3
  # ...additional configuration if needed

Then restart the stack:

docker compose up -d

7. Performance Optimization Tips

TipDescription
Adjust Worker CountStart with 2–3 workers and monitor CPU/memory usage (docker stats).
Database PruningThe compose file sets EXECUTIONS_DATA_PRUNE=true (keeps 7 days of history by default). Adjust EXECUTIONS_DATA_MAX_AGE if needed.
Redis MemoryRedis is limited to 512 MB with an LRU eviction policy. Monitor with docker exec redis redis-cli info stats.

8. Security Best Practices

  • User Management – Ensure N8N_USER_MANAGEMENT_DISABLED=false (default) and create separate accounts for each team member.
  • Restrict SSH Access – Update the security group to allow SSH only from your IP address.
  • Keep Secrets Safe – Store N8N_ENCRYPTION_KEY and POSTGRES_PASSWORD in a secure password manager or AWS Secrets Manager.

Happy automating!

Back to Blog

Related posts

Read more »