π Abstract
This repository 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
- π Abstract
- π Table of Contents
- ποΈ Architecture Overview
- π Deep-Dive the Solution
- π Deploy CDK Stack and Test
- π§Ή Cleanup Stack
- π Conclusion
- π References
ποΈ 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 <repository-url>
cd 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-id
CDK_DEFAULT_REGION=your-aws-region
HOSTED_ZONE_NAME=example.com
HOSTED_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 stack
pnpm run destroy
π Conclusion
This CDK solution provides a scalable, and cost-optimized infrastructure as code (AWS CDK) for running N8N on AWS ECS.









Top comments (0)