Defang Blog
n8n is blowing up. Here's how to deploy it to AWS in minutes.

Learn about n8n, how it's revolutionizing AI, and how to deploy it securely to your AWS account in 5min.
In early October 2025 n8n announced a huge US$180 million Series C funding round. Investors including Accel and NVentures valued the open‑source automation platform at US$2.5 billion. The reason is clear: n8n isn’t just a Zapier clone; it has evolved into a platform for AI orchestration. According to n8n’s founder, the current AI landscape oscillates between fully autonomous models and rigid rule‑based routing. n8n strives to strike a balance by giving builders control over “how much autonomy to grant” and building in orchestration and coordination so humans and agents work together. Flexible deployment is part of that promise: teams can self‑host n8n on their own infrastructure to keep data private and to integrate sensitive systems while using external data and third-party services as well.
Yet self‑hosting n8n isn’t trivial. A typical production setup involves configuring PostgreSQL, handling SSL certificates, tuning databases and scaling containers. Guidance from production‑grade self‑hosting guides point out that you have to handle all kinds of configuration across your database and services, and failures can lead to data loss or outages. For teams without a dedicated DevOps engineer this can be a deal‑breaker. That’s where Defang comes in. Defang wraps your Docker Compose project in cloud‑native infrastructure, handling secrets, networking and more for you. In this post we’ll walk through the n8n sample template and show how you can deploy a production‑ready n8n instance on your own AWS account in just a few commands.
Why build with n8n?
- Flexible AI workflow automation – n8n lets you build multi‑step agents either by dragging nodes on a canvas or by writing code. You’re free to integrate any large‑language model and over 500 third‑party integrations. The platform explicitly supports running your own AI models and even hosting the entire stack on‑premises. This flexibility is why organisations as different as Wayfair, Microsoft and the United Nations have adopted it.
- Self‑host on your own terms – by default n8n uses SQLite, but the project supports PostgreSQL and other production databases. You can enable SSL, control connection pools and even run the editor behind your own domain. You can also supply a custom encryption key so credentials stored in the database remain secure.
The Defang n8n template
The Defang sample for n8n adapts the official n8n Docker Compose example to fit Defang’s deployment model. At its core, the project contains two services:
- A PostgreSQL container to persist workflow data.
- An n8n container configured to connect to the database and expose the UI on port
5678
.
Defang takes this Compose file and wires it into your chosen cloud provider. Secrets such as the database password and encryption key are stored outside of Git using defang config
, and Defang provisions DNS, certificates and load balancers for you.
Step 1 – Generate the project
Start by installing the Defang CLI. The CLI lets you scaffold a sample and deploy it:
During generation you can search for n8n and give your project a name. This creates a directory containing the Compose file and a README.md
with instructions.
Step 2 – Configure secrets
n8n uses a database password and an encryption key to secure credentials. Defang stores these values in your cloud’s parameter store. The sample exposes the following environment variables:
POSTGRES_PASSWORD
→ Password for the Postgres database
→ Recommended: generate a random value withdefang config set POSTGRES_PASSWORD --random
N8N_ENCRYPTION_KEY
→ Key used by n8n to encrypt credentials
→ Recommended: generate a random value withdefang config set N8N_ENCRYPTION_KEY --random
DB_POSTGRESDB_SSL_ENABLED
→ Enables SSL when connecting to the database
→ Recommended: true
in production; false
in local development
DB_POSTGRESDB_SSL_REJECT_UNAUTHORIZED
→ Whether to reject unauthorized certificates
→ Recommended: false
when using Amazon RDS without custom certificates;true
when running locally
To configure these secrets run:
If you plan to deploy into your own AWS account, authenticate with the AWS CLI (by setting environment variables like AWS_PROFILE
) before running Defang. You can also run the sample in the Defang Playground without any provider configuration.
Step 3 – Deploy
Deploying is a single command:
Defang reads your Compose file, replaces any ${VAR}
references with values from the Defang config, and spins up resources. Under the hood Defang provisions:
- An ECS task (or equivalent) to run the n8n container.
- An RDS instance to host PostgreSQL.
- Route 53 entries for both internal service discovery and public access.
- TLS certificates and load balancers to terminate HTTPS.
By comparison, manual self‑hosting would require you to set up Docker Compose on an EC2 instance, configure volumes and manage updates yourself. Defang automates that complexity and manages secrets using the provider’s secret manager.
After a few minutes the CLI will print the URL of your n8n instance. It will look something like https://n8n--5678.n8n.myusername.defang.app
. Open it in your browser. n8n will prompt you for a username and password; you can skip personalisation if you don’t need it.
Step 4 – Create credentials in n8n
One of the most powerful features of n8n is its credential system. Credentials (e.g., OAuth for Google, Slack tokens, API keys) are stored encrypted in the database using the N8N_ENCRYPTION_KEY
you set earlier. When adding a credential in the n8n UI you’ll see environment variables like N8N_HOST
and N8N_PORT
pre‑filled. These variables initially contain the service name (e.g., n8n:5678
), but Defang automatically resolves them to the public DNS of your deployed service. Simply accept the suggested URL when configuring OAuth redirect URIs in Google or other providers.
For example, to configure Gmail you would:
- Click Try a prebuilt agent → Email Triage Agent in the n8n UI.
- Select Create new credential for Gmail.
- Copy the callback URL shown (it should match the domain Defang created) into your Google Cloud OAuth configuration.
- Complete the OAuth flow and test the agent.
What’s happening in AWS?
When you look into your AWS console you’ll see how Defang maps Compose concepts into native services:
- The n8n container runs as a task in an ECS cluster. You can view logs and scale up tasks just like any Fargate workload.
- PostgreSQL runs in Amazon RDS. You’ll find a managed database with backups, encryption and metrics enabled.
- Route 53 hosts two DNS zones: a private zone used for internal service discovery (so the n8n service can reach the database via its Compose hostname) and a public zone for your application’s domain. Defang automatically creates
A
andCNAME
records for you. - For local development you can run
docker compose -f compose.dev.yaml up
, which starts both services on your machine and exposes n8n athttp://localhost:5678
.
This infrastructure makes it easy to go from a prototype to a production cloud deployment without hand‑crafting Terraform or Pulumi scripts.
Go further: build AI agents with n8n
With your self‑hosted n8n instance running, you can start building agentic workflows. The platform lets you combine code and UI: write JavaScript or Python directly in nodes, merge branches, call LLMs and integrate arbitrary APIs. You can also take advantage of n8n’s new Evaluations and Data Tables features to experiment with prompts and persist structured data.
Because you’re self‑hosting, your data never leaves your environment. You can connect n8n to internal services (databases, ticketing systems, CRMs) without exposing them to a third‑party SaaS. At the same time, Defang handles networking, certificates and more for you.
Conclusion
The combination of n8n and Defang gives you the best of both worlds: a powerful AI orchestration platform and a painless way to run it in your own cloud. n8n’s recent funding round underlines how important orchestration and coordination are for real‑world AI applications, while Defang’s deployment model removes the DevOps burden. By generating the n8n sample, configuring a handful of secrets and running defang compose up
, you can stand up an instance of n8n in your AWS account in minutes.
We’d love to see what you build. Clone the sample, deploy it to your cloud of choice and share your workflows with the community. Whether you’re triaging emails, automating incident response or orchestrating agents, this template is a solid foundation.