Self-Host n8n on AWS EC2 with Docker - Install to First Login
Description and use
n8n and Postgres containers are up and running on an EC2 instance, with encrypted credentials and persistent storage, ready for first login and future hardening.
Problem
Deploy a self‑hosted n8n instance on an Amazon Linux 2023 EC2 instance without SaaS seat fees or execution caps, ensuring reproducible build and secure credential storage.
Outcome
n8n and Postgres containers are up and running on an EC2 instance, with encrypted credentials and persistent storage, ready for first login and future hardening.
Workflow
- Launch an Amazon Linux 2023 EC2 instance (t3.small or larger) with a security group allowing SSH from your IP and optionally port 5678 from your IP.
- SSH into the instance as ec2-user.
- Install Docker engine:
sudo dnf install -y dockerand enable it:sudo systemctl enable --now docker. - Install Docker Compose v2 plugin: create
/usr/local/lib/docker/cli-plugins, download the binary, make it executable, and verify withsudo docker compose version. - Clone the self‑host‑n8n‑on‑ec2 repo:
git clone https://github.com/simplynadaf/self-host-n8n-on-ec2.gitandcd self-host-n8n-on-ec2. - Edit
compose/docker-compose.yml: setN8N_ENCRYPTION_KEYto a 32+ character random string, setDB_POSTGRESDB_PASSWORDandPOSTGRES_PASSWORDto the same strong password, and optionally adjust other environment variables. - Run
sudo docker compose up -dfrom thecomposedirectory to pull images and start containers. - Verify service: `curl -s -o /dev/null -w 'n8n -> HTTP %{http_code} ' http://localhost:5678` should return HTTP 200.
- Open
http://<PUBLIC_IP>:5678in a browser, complete the setup wizard to create the owner account. - (Optional) For production, stop publishing port 5678, use Caddy or another reverse proxy, move secrets to AWS Secrets Manager, and tighten the security group.
- Record date: 2026-09-20T10:15:30.749Z