Skip to content

Self-Hosted n8n on AWS ECS with CDK

Posted on:October 13, 2026 at 10:20 PM

Self-hosted n8n on AWS ECS with CDK

Abstract

n8n is a workflow automation platform for connecting services and automating repeatable tasks. This project uses the AWS Cloud Development Kit (CDK) with TypeScript to provision infrastructure for a self-hosted n8n deployment on AWS.

The architecture runs n8n services on Amazon ECS Fargate, persists workflow data in PostgreSQL on Amazon RDS, and uses Amazon ElastiCache for Redis for queue management. A Network Load Balancer distributes HTTPS traffic to the n8n main service, while AWS Cloud Map supports internal service discovery.

Table Of Contents

Open Table Of Contents

Architecture overview

n8n architecture flow

The CDK stack provisions the supporting AWS services and compute environment:

  • Multi-AZ VPC with public, private, and isolated subnets.
  • Amazon ECS Fargate to run the containerized n8n services with autoscaling capabilities.
  • Network Load Balancer (NLB) to distribute HTTPS traffic to n8n main service instances.
  • Amazon RDS for PostgreSQL for persistent workflow data.
  • Amazon ElastiCache for Redis for BullMQ queue management.
  • AWS Cloud Map for internal service discovery.

Detailed n8n infrastructure diagram

The deployment includes separate n8n main and worker services. The main service provides the n8n interface, while workers process jobs from the Redis-backed queue.

Deep dive

The main service and workers run as ECS tasks in the Fargate cluster. The NLB routes incoming HTTPS traffic to the main service; workers process queued executions separately. PostgreSQL stores n8n’s persistent data, and Redis supports queue-based execution.

This separation allows the web-facing service and background job processing to be deployed and scaled as distinct ECS services. AWS Cloud Map provides service discovery for internal communication.

Deploy and verify

Prerequisites

  • An AWS account with permissions to create the required resources.
  • AWS CLI installed and configured.
  • Node.js 16 or later and pnpm.
  • AWS CDK CLI (npm install -g aws-cdk).
  • A Route 53 hosted zone if you want to configure a custom domain.

Environment setup

Clone the repository and install dependencies:

git clone https://github.com/vumdao/aws-cdk-self-hosted-n8n-infra.git
cd aws-cdk-self-hosted-n8n-infra
pnpm install

Create a .env file in the project root with your AWS account and region. Set the hosted zone values when using a Route 53 custom domain:

CDK_DEFAULT_ACCOUNT=your-aws-account-id
CDK_DEFAULT_REGION=your-aws-region
HOSTED_ZONE_NAME=example.com
HOSTED_ZONE_ID=Z1234567890ABC

Synthesize and deploy

Synthesize the CloudFormation template and review the changes before deploying:

pnpm run synth
pnpm run diff
pnpm run deploy

After deployment, verify the ECS cluster and services are healthy. Check the main service, worker service, Network Load Balancer, and target group to confirm that tasks are running and registered.

ECS cluster with n8n services

n8n main service

n8n worker service

Network Load Balancer

ECS target group

Test an n8n workflow

Open the n8n UI using the NLB DNS name or your configured custom domain. For example:

https://n8n.simflexcloud.com

n8n workflow editor

Create a test workflow, such as sending an inspirational quote from an internet service to Slack each day. Run it and confirm that the message arrives in the configured Slack channel:

Slack message delivered by an n8n workflow

Cleanup

Destroy the CDK stack after testing to avoid ongoing AWS charges:

pnpm run destroy

Conclusion

This project demonstrates how to run self-hosted n8n on AWS with infrastructure defined in CDK. ECS Fargate hosts the main and worker services, PostgreSQL provides persistent storage, and Redis supports queue processing. The result is a modular deployment that can be managed and reproduced through code.


References: