The brief: automate lead classification from a Gmail inbox
The idea was simple to describe and less simple to deploy reliably: a new email lead lands in a Gmail inbox, a workflow classifies it, and drafts an appropriate response using an LLM — without a human touching it first. I built this using n8n, an open-source workflow automation tool, self-hosted on a single EC2 instance.
This was my first project where "it works on my machine" wasn't good enough. It had to run continuously, unattended, for a real client.
Decision 1: why EC2, not Lambda
My first instinct was to reach for Lambda, since I'd already been using it for smaller event-driven tasks. But n8n is a persistent application with its own web UI and internal state — it's not a single function that runs and exits. That ruled out Lambda immediately and made EC2 the obvious fit: one long-running instance, one install, always-on.
This was the first time I actually had to choose between compute options based on the shape of the workload, rather than picking the service a tutorial happened to use. That distinction — "does this need to persist state and run continuously, or does it run once and finish?" — turned out to be one of the most useful questions I now ask before starting any build.
Decision 2: locking the instance down
Once n8n was running and reachable, the obvious next problem was that "reachable" and "reachable by anyone" are the same thing unless you actively prevent it. My security group started open to the world on port 443 while I was testing — which is a completely normal beginner move, and also exactly the wrong final state.
What I actually did to fix it:
- Restricted inbound access to just the ports the workflow needed, not a broad range
- Made sure the webhook endpoint used HTTPS rather than plain HTTP, since it was going to receive real (if low-sensitivity) data
- Learned to treat "it works" and "it's safe to leave running" as two separate milestones, not one
Decision 3: the webhook trigger, and why timing matters
The workflow is triggered by a webhook call when a new email arrives, rather than n8n polling the inbox on a schedule. This was a small design choice with a real consequence: polling means the response can lag by however long your polling interval is, while a webhook responds close to instantly. For an automation meant to feel responsive to a client's leads, that difference mattered more than I expected going in.
What I'd tell someone building their first "real" AWS project
The gap between a tutorial project and a first real project isn't the AWS services involved — it's the number of decisions that don't have one obviously correct answer. A few that made the biggest difference for me:
- Match the compute service to the shape of the workload, not to whichever service you already know. Persistent and stateful usually means EC2 or containers; short-lived and event-driven usually means Lambda.
- Treat "publicly reachable" as a decision, not a default. Lock down inbound access before you consider the project finished, not after.
- Prefer triggers over polling wherever the service supports it — it's usually both faster and cheaper.
None of this was hard, exactly. It just wasn't covered by the tutorials I'd been following, because tutorials rarely have to survive contact with an actual, ongoing use case.
Loading article