
Self-Hosted N8N on AWS ECS with AWS CDK Typescript
Deploy Self-Hosted n8n on AWS with CDK (TypeScript) — A complete Infrastructure as Code solution using ECS Fargate, PostgreSQL RDS, and Redis for a scalable, resilient, and cost-efficient workflow automation platform.
📋 Abstract
This artic provides Infrastructure as Code (IaC) solution for deploying a self-hosted N8N workflow automation platform on AWS using the AWS Cloud Development Kit (CDK). The solution implements a scalable, cost-optimized, and highly available architecture leveraging AWS ECS Fargate, PostgreSQL RDS database instance, and ElastiCache Redis for queue management.
📑 Table of Contents
🏗️ Architecture Overview
Key Components:
- VPC with Multi-AZ Subnets: Isolated network with public, private, and isolated subnets across multiple availability zones
- Network Load Balancer (NLB): Distributes HTTPS traffic to N8N main service instances
- ECS Fargate Cluster: Runs containerized N8N services with auto-scaling capabilities
- RDS PostgreSQL: Multi-AZ managed database for workflow data persistence
- ElastiCache Redis: In-memory cache for BullMQ job queue management
- AWS Cloud Map: Service discovery for internal service-to-service communication
🔍 Deep-Dive the Solution
🚀 Deploy CDK Stack and Test
📋 Prerequisites
Before deploying, ensure you have:
- AWS CLI installed and configured (
aws configure)
- Node.js 16+ and pnpm installed
- AWS CDK CLI installed (
npm install -g aws-cdk)
- An AWS account with appropriate permissions
- A Route53 hosted zone (optional, for custom domain)
⚙️ Environment Setup
- Clone the repository:
git clone https://github.com/vumdao/aws-cdk-self-hosted-n8n-infracd aws-cdk-self-hosted-n8n-infra- Install dependencies:
pnpm install- Configure environment variables: Create a
.envfile in the root directory:
CDK_DEFAULT_ACCOUNT=your-aws-account-idCDK_DEFAULT_REGION=your-aws-regionHOSTED_ZONE_NAME=example.comHOSTED_ZONE_ID=Z1234567890ABC🚀 Deployment Steps
- Synthesize CloudFormation template:
pnpm run synth- Review the changes:
pnpm run diff- Deploy the stack:
pnpm run deploy✅ Verify Deployment
After successful deployment, verify the resources in AWS Console:
1. ECS Cluster:

The ECS cluster shows both N8N services running with the configured task definitions and capacity providers.
2. Main Service:

The N8N main service displays running tasks, auto-scaling configuration, and health status.
3. Worker Service:

The worker service shows active workers processing queued jobs with concurrency settings.
4. Network Load Balancer:

The NLB shows the listener configuration and DNS name which is used to create alias record in route53.
5. Target Group:

The target group displays registered ECS tasks with health check status and routing configuration.
🧪 Testing N8N Workflows
1. Access N8N UI:
Navigate to your NLB DNS name or custom domain (if configured):
https://n8n.simflexcloud.com
The N8N interface shows the workflow editor where you can create, test, and monitor automation workflows.
2. Create a Test Workflow:
Example workflow: Send an inspirational quote from internet to Slack daily
3. Verify Execution:

The Slack integration demonstrates successful workflow execution with the message being delivered to the configured Slack channel.
🧹 Cleanup Stack
To avoid ongoing AWS charges, destroy all resources:
# Destroy the CDK stackpnpm run destroy🎉 Conclusion
This CDK solution provides a scalable, and cost-optimized infrastructure as code (AWS CDK) for running N8N on AWS ECS.
📚 References
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article