In AWS CloudFormation, what exactly does stack drift detection compare, and what does CloudFormation do about the drift it finds?
answer
- expected template values versus live configuration
- a report, not a repair
- runs only when you ask
- per-resource status plus property diff
- re-applying an unchanged template fixes nothing
basics
~20 sDrift detection compares a stack's live resource configuration against the values its template and parameters expect, then reports the differences. It is read-only and on demand: CloudFormation never reverts drift for you and never watches resources continuously.
solid answer
~50 sCloudFormation keeps the template it last applied to a stack plus the parameter values used with it; together those are the *expected* configuration. When you start a drift detection run, it reads the current configuration of each stack resource from the underlying service and compares the two, resource by resource and property by property. The output is a report: each resource comes back `IN_SYNC`, `MODIFIED`, `DELETED` or `NOT_CHECKED`, and modified resources carry the expected and actual values of the properties that differ. That is all it does — it does not roll anything back, does not block the next stack update, and does not update the template to match reality. Fixing drift is a separate, deliberate act: either change the resource back, or change the template to describe what is now true and update the stack.
go deeper
Know the one-line definition: it compares live resources against what the template and parameters said, and reports differences without fixing them. Say plainly that it runs only when you start it.
Be ready to name the per-resource statuses and describe the two ways drift is resolved — change the resource back, or change the template and update. Explain why an unchanged template produces no update at all.
Show judgment about what a clean report is worth: it is a point-in-time sample of a partial set of properties. Talk about scheduling detection and about preventing console writes rather than detecting them afterwards.
Own the position that drift is a symptom of a broken change path, not just a report to act on. Decide where detection sits in the delivery pipeline and what an organisation does when the on-call fix and the code inevitably diverge.
## What CloudFormation means by "expected" Every CloudFormation stack has a stored template — the exact one that was last successfully applied — plus the parameter values it was applied with. Resolve the parameters, conditions and intrinsic functions in that template and you get a concrete statement of what every resource in the stack is supposed to look like: this bucket has versioning enabled, this security group has exactly these two ingress rules, this table has this billing mode. That resolved picture is the **expected configuration**. Drift is what happens when the real world stops matching it. Somebody opens the console at 3am to unblock an incident and adds an ingress rule. A support engineer flips a setting through a service API. An automated tool with write access to the account edits a tag. None of that goes through CloudFormation, so the stored template still describes the old shape while the live resource has moved on. ## What a detection run actually does Drift detection is a read operation. When you start it, CloudFormation walks the stack's resources, calls the owning service's read APIs to fetch each resource's current configuration, and compares that against the expected values. Each resource lands in one of four states: - `IN_SYNC` — the properties CloudFormation compared all match. - `MODIFIED` — at least one compared property differs; the report carries the expected value, the actual value and the path of each differing property. - `DELETED` — the resource no longer exists; something removed it outside the stack. - `NOT_CHECKED` — CloudFormation made no comparison, usually because drift detection is not supported for that resource type. Those per-resource results roll up to a stack-level status. If anything is `MODIFIED` or `DELETED`, the stack is `DRIFTED`. ## It reports; it does not repair This is the point candidates most often get wrong. A drift report changes nothing. The drifted resource keeps its hand-edited configuration, the stack keeps its stored template, and the next deployment proceeds as if nothing happened. There is no auto-revert switch and no "enforce" mode. So what do you do with a `MODIFIED` result? You make a decision, and there are only two honest options. **Make reality match the code.** Somebody made a change that should not stand, so you put the resource back. Beware of the obvious-looking move here: re-applying the same template does not do it. A stack update diffs the *new* template against the *stored* one, not against live resources — if the template has not changed, CloudFormation answers `No updates are to be performed` and the drift survives. You need an update that genuinely touches the drifted property, or you fix the resource directly. **Make the code match reality.** The change was legitimate and should have gone through the pipeline. Edit the template to describe the new value and update the stack, so the recorded expectation and the live resource agree again. What you must not do is leave it. A drifted resource means the template no longer describes production, which quietly breaks the promise the whole tool rests on: that you can redeploy this stack somewhere else and get the same thing. ## On demand, not continuous CloudFormation does not sit and watch. Drift is evaluated only when a detection run is started — from the console, from the API, or from something you schedule yourself. A stack that says `IN_SYNC` is telling you about the moment detection ran, not about now. Somebody can drift a resource thirty seconds after a clean report and nothing will notice until the next run. That is why teams that care about drift schedule detection rather than clicking it: a periodic job that starts detection across the estate and alerts on the drifted count. ## What it does not look at Drift detection is scoped to the resources the stack manages. It says nothing about resources someone created *next to* the stack — a hand-made security group in the same VPC is invisible to it, because the stack never claimed to own it. It also only looks at configuration, never at data: bucket contents, table rows and log entries are not properties, so they are not drift. And its coverage inside the stack is partial — drift support exists per resource type and per property, which is why `NOT_CHECKED` shows up constantly and why a clean report is weaker evidence than it looks.
- A resource comes back MODIFIED and you want the template's value to win. Why is re-running the same stack update usually not enough?Because a CloudFormation update diffs the submitted template against the stack's stored template, not against live resources. If the template is unchanged there is nothing to do and the API answers `No updates are to be performed`, leaving the drift in place. You need an update that actually changes the drifted property — or you correct the resource directly and re-run detection to confirm.
- Does drift detection tell you about a resource somebody created by hand alongside the stack?No. Detection only walks resources the stack manages, comparing each against its template entry. A security group created by hand in the same VPC was never claimed by the stack, so it does not appear in the report at any status. Finding unmanaged resources is a separate inventory or account-compliance problem, not something a stack drift report answers.
- Is a stack update blocked or warned about if the stack is currently drifted?No. CloudFormation does not consult drift status before an update, and an update is not a drift check. It computes changes from the template diff and applies them, which can silently overwrite a hand edit — or leave it untouched if the update never touches that property. If drift matters to your pipeline, run detection explicitly before deploying.
saying these in an interview costs you the question
- Says drift detection automatically reverts the resource to the template
- Believes CloudFormation monitors stacks for drift continuously
- Assumes IN_SYNC means every property of every resource was checked
- Confuses a drift report with a change set preview of a pending update
- Thinks re-applying the same template always corrects a drifted property