Configuration design
This note answers one question: why does n8n.yaml look the way it does? It decided that the file describes n8n and not AWS, that every resource is chosen by a kind, and that a typo is an error and never silently ignored. The models are pydantic classes, and the JSON Schema and the reference are derived from them.
Read it when you extend the grammar. To write a file, use the configuration reference.
Design principles
- One file, one deployment. One file maps to one CDK app and to a set of CloudFormation stacks named
<name>-network,<name>-data,<name>-n8n, plus<name>-edgein us-east-1 when needed. - Describe n8n, not AWS. Top-level sections follow n8n concepts (
topology,database,queue,storage,auth). AWS-only knobs live underruntime.ecs,runtime.eksandaws. - Every resource is
kind-discriminated. One key,kind, picks the implementation, and the other keys of that block belong to that kind only. Pydantic models this as a discriminated union, so a typo or a key that belongs to another kind is an error, not silently ignored. createorexistingeverywhere. Each resource we might own (VPC, ECS or EKS cluster, database, cache, bucket, Cognito, certificate, hosted zone, KMS key, WAF, secrets) acceptskind: existingwith identifiers, or anexternalkind when it lives outside AWS's control.- Layered defaults. Values resolve as: built-in defaults <
profile< the file <--set key=valueon the CLI.n8n-on-aws planshows the resolved value and where each one came from. - No secrets in YAML. Secrets are always references:
{secret: <name-or-arn>}or{secret: <name>, key: <json-key>}. - Escape hatch.
n8n.envpasses any n8n variable as-is, after the generated ones. A variable we generate can be overridden only with a warning.
How the models are written
The excerpt below shows the pattern: strict models, a discriminated union per resource, and shared bases for what several kinds have in common.
from typing import Annotated, Literal
from pydantic import BaseModel, ConfigDict, Field
class Strict(BaseModel):
model_config = ConfigDict(extra="forbid")
class SecretRef(Strict):
secret: str
key: str | None = None
class _ManagedPostgres(Strict):
engine_version: str = "17"
backup_retention_days: int = Field(7, ge=1, le=35)
deletion_protection: bool = True
pool_size: int = Field(4, ge=1)
class AuroraServerless(_ManagedPostgres):
kind: Literal["aurora-serverless"]
min_acu: float = Field(0.5, ge=0, le=256)
max_acu: float = Field(4, ge=1, le=256)
readers: int = Field(0, ge=0, le=15)
class ExternalPostgres(Strict):
kind: Literal["external"]
host: str
port: int = 5432
name: str = "n8n"
schema_: str = Field("public", alias="schema")
credentials: SecretRef
ssl: Literal["disable", "require", "verify-full"] = "verify-full"
security_group_id: str | None = None
pool_size: int = Field(4, ge=1)
Database = Annotated[
Sqlite | AuroraServerless | AuroraProvisioned | Rds | ExternalPostgres,
Field(discriminator="kind"),
]Cross-field rules (the validation rules of the options note) live in a single @model_validator(mode="after") on the root Deployment model. They return all errors at once, each with a path (database.kind) and a hint. profile defaults are applied in a mode="before" validator by deep-merging the profile dictionary under the user's data. That keeps "explicit beats profile" trivially true, and the plan can report where each value came from.
The JSON Schema is exported from the models (n8n-on-aws schema > schema/v1.json). Samples start with # yaml-language-server: $schema=... for editor completion.
What the grammar compiles to
| Section | ECS | EKS |
|---|---|---|
topology.* | one ECS service per role, task def with n8n + runners containers | Helm values: main, webhookProcessor, worker blocks; runner sidecars on workers (see the EKS guide) |
workers.scale_on: queue-depth | CloudWatch agent sidecar on main scrapes n8n's queue gauges into the n8n-on-aws namespace; step scaling out on waiting jobs (from zero workers), in when the jobs in flight fit on one worker less, plus a CPU policy that never scales in | KEDA redis scaler on the BullMQ waiting list <prefix>:jobs:wait, target jobs per worker; the prefix is {n8n} on ElastiCache Serverless and bull otherwise. With keda: none: the chart's HPA on CPU, and a C2 warning |
database, queue, storage.bucket | shared <name>-data stack | same |
auth.alb-* | ALB listener rules: bypass list → forward; default → authenticate then forward | ALB Ingress annotations (alb.ingress.kubernetes.io/auth-*) on the editor paths; the public paths are Ingresses of their own without them (see the EKS guide) |
auth.cloudfront-cognito | Lambda@Edge viewer-request function in the <name>-edge stack (us-east-1); Cognito pool and public client in <name>-n8n, which writes their IDs to an SSM parameter in us-east-1; one CloudFront behavior without the function per public path | same, with the controller's internal ALB as a VPC origin (see the EKS guide) |
| secrets | ECS secrets: from Secrets Manager | External Secrets Operator, reading Secrets Manager through Pod Identity (see the EKS guide) |
A change to the grammar touches four places together: the models (config/models.py), the rules (config/rules.py), the JSON Schema (make schema) and the configuration reference. The test suite fails when the reference misses a key of the schema.