CloudFormation explained in one sentence: it is the Amazon Web Services service that lets you describe your cloud infrastructure in a text file and have AWS build it for you, in the right order, every time. Should your team use it? If you run anything serious on AWS, yes — CloudFormation turns manual console clicking into repeatable, version-controlled infrastructure, so an environment can be rebuilt exactly rather than remembered vaguely.
The problem it solves is familiar to anyone who has built infrastructure by hand. A developer creates a virtual private cloud in the console, adds a database, wires up security groups, and everything works. Six months later nobody can say exactly what was created, in which order, or with which settings, and rebuilding it in a second region becomes a slow, error-prone exercise. CloudFormation replaces that guesswork with a template: a single declarative file that states what should exist, and lets AWS work out how to create it.
Key takeaways
- CloudFormation is AWS infrastructure as code: you declare resources in a YAML or JSON template and AWS provisions them as a stack.
- A stack is a group of resources managed as one unit, so you can create, update or delete a whole environment in a single operation.
- Change sets preview exactly what an update will do before anything is applied, including which resources will be replaced.
- Drift detection compares live resources with the template and flags manual changes made outside CloudFormation.
- StackSets extend the same idea across many accounts and regions from one template.
- CloudFormation is strongest for AWS-only estates; multi-cloud teams usually pair it with or replace it by another tool.
What is AWS CloudFormation?
CloudFormation is an infrastructure as code service from AWS. Instead of creating resources one by one in the console, you write a template that declares the resources you want — a virtual private cloud, subnets, a database, a load balancer, the permissions that connect them — and CloudFormation creates, updates and deletes those resources together as a single unit called a stack.
Templates are written in YAML or JSON. YAML is the more common choice because it is shorter and easier to read, but both formats describe exactly the same thing. A template is declarative, which means it states the desired end state rather than a list of steps. You say that a storage bucket with a particular name should exist; CloudFormation decides the order of operations, handles dependencies between resources, and rolls back if something fails.
This is a different mental model from scripting. A script says do this, then do that, and if step three fails you are left with a half-built environment. A template says this is what the world should look like, and CloudFormation works towards that state, tracking every resource it creates so it can update or remove it later. That tracking is what makes a stack more than a one-off deployment: it is a living record of an environment.
How CloudFormation works
The workflow has four stages. First, you write the template, declaring resources, their settings, and the values that vary between environments, such as instance size or database name. Second, you create a stack from the template, supplying those variable values as parameters. Third, CloudFormation provisions the resources, resolving dependencies so that, for example, the network exists before the database that sits inside it. Fourth, you manage the stack over time: change the template, update the stack, and CloudFormation applies only the difference.
Rollbacks are part of the design. If a stack creation fails partway through, CloudFormation removes the resources it already created, so you do not end up with a half-finished environment. If a stack update fails, it rolls back to the previous working state.
Inside a template: the main sections
A template is organised into sections, each with a job. The format version and a short description sit at the top. Parameters accept inputs at deployment time, such as the environment name or the instance type, so one template can serve development, staging and production. Mappings hold fixed lookup values, such as which machine image to use in each region, while conditions let parts of the template apply only when a parameter says so.
The resources section is the heart of the template. Each entry names a resource type, such as an S3 bucket or a relational database, and sets its properties. Resources can reference each other: a compute instance can take the identifier of the network it belongs to, and CloudFormation resolves those references automatically. The outputs section exposes useful values after deployment, such as a load balancer address or a database endpoint, so other stacks or applications can consume them.

Change sets: preview before you apply
One of the most valuable habits in CloudFormation is never updating a stack blind. A change set is a preview of exactly what an update will do: which resources will be modified, which will be replaced, and which will be left alone. You create the change set, read it, and only then execute it. This turns infrastructure changes into something you can review, much like reviewing a code change before merging it.
Replacement deserves particular care. Some property changes can be applied in place, such as resizing an instance, while others force CloudFormation to delete the old resource and create a new one. Changing a database name, for example, typically replaces the database — and with it, the data inside, unless a snapshot or retention policy protects it. The change set tells you this in advance, which is the difference between a planned migration and an accidental data loss.
Drift detection and stack policies
Infrastructure drifts. Someone makes a quick fix in the console, a colleague tweaks a security group during an incident, and the live environment quietly stops matching the template. Drift detection compares the actual configuration of stack resources against the template and reports which resources have changed.
StackSets: one template, many accounts and regions
A single stack lives in one account and one region. StackSets remove that limit. A StackSet takes one template and deploys it as stacks across many accounts and regions, from a central administrator account. This is how organisations roll out the same baseline — logging, audit trails, standard networking, security guardrails — to every account they own, without copying templates by hand.
CloudFormation compared with the alternatives
CloudFormation is not the only way to manage AWS infrastructure, and the alternatives solve different problems. The table below compares the main options on the dimensions that matter most to a team choosing between them.
| Approach | How you define infrastructure | Main strength | Main weakness | Best for |
|---|---|---|---|---|
| CloudFormation | Declarative YAML or JSON templates | Native to AWS, with rollback, drift detection and StackSets | AWS only, and templates get verbose at scale | AWS-only teams that want a managed, native service |
| AWS CDK | Real programming languages that generate templates | Loops, conditions and reusable components | Still deploys through CloudFormation, so the same limits apply | Developers who prefer code to long YAML files |
| Terraform | Declarative configuration in its own language | Works across many cloud providers and services | You run the state and the tooling yourself | Multi-cloud estates and teams standardising on one tool |
| Console and CLI | Manual clicks or imperative commands | Fast for one-off experiments | Nothing is recorded, reviewed or repeatable | Learning, demos and emergencies only |
Best for: teams that live entirely on AWS and want infrastructure as code without running extra tooling — CloudFormation is the default, lowest-friction choice, and it pairs naturally with the deployment models your applications already use.
The honest trade-off is scope. CloudFormation knows AWS deeply and other clouds not at all. If your estate spans AWS and another provider, a multi-cloud tool will serve you better, even though it means managing state and upgrades yourself.
When CloudFormation fits — and when it does not
CloudFormation fits best when infrastructure changes are frequent, environments must be reproducible, and auditability matters. Development teams that spin up a fresh environment per feature branch, regulated teams that must show how each resource came to exist, and platform teams rolling out standard baselines all get real value from it. It also fits when the team is small: there is no server to run, no state file to protect, and no upgrade cycle to manage, because AWS operates the service.
It fits less well in three situations. Very large templates become hard to read and slow to update, so teams usually split them into nested stacks or separate stacks per layer. Workloads that span multiple clouds need a tool that speaks to all of them. And teams that want a real programming language — loops, functions, unit tests on infrastructure — usually prefer the AWS CDK, which generates CloudFormation templates from code and keeps the same deployment engine underneath.
A practical middle path is common: use CloudFormation, or the CDK on top of it, for the AWS foundation, and let application deployment tools handle what runs on top. That separation matches how the pieces actually work — CloudFormation provisions the platform, while GitOps tooling keeps applications in sync with what is committed in version control.
Getting started checklist
Use this checklist for your first production stack. It covers the decisions that prevent the most common early mistakes.
- Store the template in version control and treat changes like code changes, with review before deployment.
- Parameterise the values that differ between environments, such as names, sizes and regions, instead of copying the template.
- Create a change set for every update and read it before executing, paying attention to any resource marked for replacement.
- Set deletion and snapshot policies on stateful resources such as databases so an accidental delete does not destroy data.
- Enable drift detection on important stacks and review its results on a regular schedule.
- Split large templates into nested stacks or separate stacks per layer before they become hard to read.
- Give stacks clear names that include the environment and the application, so the console stays readable at scale.
- Test the template in a non-production account first, and delete the test stack to confirm clean teardown works.
Frequently asked questions
Is CloudFormation free to use?
CloudFormation itself carries no charge for creating and managing stacks; you pay only for the AWS resources the stacks create, such as compute and storage. That makes it easy to adopt, since the cost of trying it is the cost of the resources in a test stack.
What is the difference between a template and a stack?
A template is the file that declares what should exist. A stack is the live result: the actual resources created from that template in one account and region, managed as a single unit. One template can produce many stacks, for example one per environment.
Can CloudFormation manage resources outside AWS?
CloudFormation manages AWS resources and a set of supported third-party resources through registry extensions. It is not a multi-cloud tool, so resources in other clouds need a different tool or a separate process.
What happens if a stack update fails?
CloudFormation rolls the stack back to its previous working state, removing any partially created resources from the failed update. You can then inspect the failure events, fix the template, and try the update again.
How do I find out why a stack failed?
Open the stack events in the console or query them through the command line interface. Events list each resource operation in order, with the reason for any failure, which is usually enough to identify the misconfigured property.
Should I learn CloudFormation or the AWS CDK first?
Learn CloudFormation first. The CDK generates CloudFormation templates, and understanding stacks, change sets and drift makes CDK output far easier to read and debug. The CDK then removes the verbosity, not the concepts.







