I Wrote My First CloudFormation Template by Hand: What It Taught Me About Infrastructure as Code
Writing my first CloudFormation template by hand forced me to make every infrastructure decision explicit — and a change set warned me before an update would have replaced a database.
I had been clicking through the AWS console for months before I wrote my first CloudFormation template. Every resource I owned — an S3 bucket here, a Lambda function there, a security group I was fairly sure I still needed — had been created by hand, in a browser, with no record of how it got there. It worked, until the day I needed to rebuild the same setup in a second environment and realised I could not remember half the settings I had chosen. That was the day the console stopped feeling fast and started feeling fragile.
CloudFormation is AWS's native way to describe infrastructure as code: you write a template, in YAML or JSON, that declares the resources you want, and CloudFormation creates them for you, in the right order, with the right dependencies. The first thing that surprised me was how honest it made me. A template cannot hide a vague decision. If a security group allows traffic on port 443, the template says so. If a bucket is public, the template says so. My console-built setup had plenty of settings I had never consciously chosen; writing them down forced me to decide, one by one, what I actually wanted.
My first template was small on purpose: one S3 bucket, one Lambda function, and the IAM role between them. It took me longer than clicking through the console would have. The first deploy failed because I had referenced a resource name that did not exist yet. The second failed because my IAM role was missing a permission the function needed. Each failure was annoying in the moment, but each one taught me something the console never had: CloudFormation rolls back when a deploy fails. Instead of leaving a half-built mess behind, it cleaned up after itself. I started to trust the deploy process in a way I never trusted my own clicking.
The idea that changed my thinking most was the change set. Before CloudFormation applies an update, you can ask it to show you exactly what will change: which resources will be modified, which will be replaced, and which will be left alone. The first time I saw a change set flag that an update would replace my database — destroying its data in the process — I felt a chill. I had been about to make the same change in the console, where nothing would have warned me. That single feature is, to me, the strongest argument for infrastructure as code: not speed, not elegance, but a pause before the irreversible.
There are trade-offs, and I will not pretend otherwise. Templates get long. A real application can need hundreds of lines, and debugging a failed deploy sometimes means reading an error message that points at the wrong line. CloudFormation's error messages are famously unhelpful — "resource failed to create" tells you almost nothing about why. And there is a real learning curve: intrinsic functions like Ref and Fn::Sub, parameters, outputs, and the difference between an update and a replacement all take time to internalise. Compared with CDK, which lets you write infrastructure in a programming language, raw CloudFormation can feel verbose. But for learning how AWS resources actually fit together, that verbosity was a feature. Nothing was hidden behind an abstraction; every resource and every permission was right there on the page.
The habit that stuck with me is simple: nothing important gets created in the console any more. If a resource matters, it lives in a template, and the template lives in version control. That means I can review a change before it happens, roll back to a previous version when something breaks, and rebuild an environment from scratch without relying on my memory. The console is still useful for looking things up and for one-off experiments. But experiments that become permanent now get written down first.
CloudFormation did not make me faster on day one. It made me slower, more deliberate, and — for the first time — able to explain exactly what my infrastructure was and why. That trade has been worth it every week since.
What is the one resource in your account that you are afraid to touch because you are not sure how it was built?
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article