CloudFormation Drift Troubleshooter
Activation
Activate this skill when the user reports CloudFormation drift. Trigger
phrases: "CloudFormation drift", "stack drift",
"StackDriftStatus DRIFTED", "ResourceDriftStatus MODIFIED",
"ResourceDriftStatus DELETED", "ResourceDriftStatus ADDITION",
"describe-stack-resource-drifts", "detect-stack-drift", "resource
modified outside CloudFormation", "resource deleted outside
CloudFormation", "import existing resources into stack", "drift reset",
"CloudFormation Hooks", "CDK drift", "nested stack drift".
Mindset
One-line takeaway: CloudFormation drift is the gap between the
template-of-record and the actual resource state. The diagnostic surface
is describe-stack-resource-drifts, which classifies each resource as
MODIFIED, DELETED, ADDITION, or IN_SYNC. The job of this skill
is to (1) confirm drift exists, (2) classify each drift by type and
severity, (3) identify the out-of-band actor and trigger, (4) choose a
resolution strategy (import, reset to drift, revert to template), and
(5) prevent recurrence.
Three facts make drift troubleshooting different from generic stack
failure triage:
Drift is not an error — it is a state. StackDriftStatus: DRIFTED
does not block the stack from being read; it warns that the next
update may not behave as the operator expects. Many stacks run DRIFTED
for months without incident. The actionable question is "which
property diverged, who changed it, and what happens if I update now?"
Each drift type has a different resolution. A MODIFIED drift
can be reset by accepting the out-of-band value into the template
(drift reset) or by reverting the resource to match the template.
A DELETED drift usually means the resource was removed manually
and must be recreated or imported-as-gone. An ADDITION drift
requires the operator to decide whether to bring the new resource
under stack management (import) or delete the out-of-band resource.
Drift on immutable properties is the dangerous case. If a drifted
property is one CloudFormation treats as requiring Replacement (e.g.,
an RDS DBInstanceIdentifier, a DynamoDB KeySchema, an S3 bucket's
BucketName), the next update will trigger resource replacement —
often the opposite of what the operator wants. Always cross-reference
each PropertyDifference against the resource's immutable-property
list before recommending update-stack.
Quick reference — drift type to resolution
| Drift type |
What it means |
Resolution options |
Risk |
MODIFIED (property changed outside CFN) |
A property on an existing stack resource was edited via console / SDK / CLI, not via stack update |
(a) Drift reset — update template to match actual, then update-stack; (b) Revert — manually set resource back to template value; (c) Import-as-truth — import-resources with the new template |
If the drifted property is immutable, update-stack triggers Replacement |
DELETED (resource deleted outside CFN) |
The physical resource backing a stack resource was deleted via console / SDK / CLI |
(a) Recreate — update-stack will recreate the missing resource; (b) Remove from template if the resource is no longer needed; (c) Mark as DeletionPolicy: Retain if intentional |
Stack update will attempt to recreate — may fail if dependencies are gone |
ADDITION (new resource not in stack) |
A new physical resource exists in the account but is not managed by the stack (visible via resource-level import scan or Config) |
(a) Import — import-resources to bring under stack management; (b) Delete the out-of-band resource; (c) Ignore if intentionally unmanaged |
Out-of-band resources are invisible to stack delete — they persist silently |
NOT_CHECKED |
Drift detection has not run for this resource (e.g., a resource type that does not support drift detection) |
Run detect-stack-drift; for unsupported types, use AWS Config rules for posture |
Hidden drift — the stack reports IN_SYNC but the resource may have diverged |
Drift on DeletionPolicy: Retain resource |
The retained resource drifts but CloudFormation does not reconcile it on stack delete |
Track separately; consider UpdateReplacePolicy: Delete if drift resets are desired |
Resource persists after stack delete regardless of drift |
Quick navigation
- Step 0 — Capture the drift signal (stack name/ARN, region,
StackDriftStatus, time of last detection, trigger source).
- Step 1 — Run / refresh drift detection
(
detect-stack-drift then poll
describe-stack-drift-detection-status).
- Step 2 — Read
describe-stack-resource-drifts and classify each
drift (MODIFIED / DELETED / ADDITION).
- Step 3 — Forensic walk: who changed it and when? (CloudTrail,
Config timeline).
- Step 4 — Assess update impact: for each
PropertyDifference,
determine if the property is immutable (Replacement required).
- Step 5 — Choose resolution: IMPORT, RESET_TO_DRIFT,
REVERT_TO_TEMPLATE, REMOVE_FROM_TEMPLATE.
- Step 6 — Validate via ChangeSet (or
create-change-set for
resource import) before applying.
- Step 7 — Decide VERDICT (ROOT_CAUSE_FOUND / NEED_MORE_INFO /
ESCALATE).
- Step 8 — Prevent recurrence (IAM policy, CloudFormation Hooks,
Conformance Pack).
STRICT output contract
Every response MUST begin with this block — no preamble, no
conversational opening:
INCIDENT: <stack name or ARN> in <region> — StackDriftStatus <status>, <N> drifted resource(s)
VERDICT: ROOT_CAUSE_FOUND | NEED_MORE_INFO | ESCALATE
ROOT_CAUSE: <MODIFIED | DELETED | ADDITION> on <LogicalResourceId (PhysicalResourceId)> — <one-sentence identifying the out-of-band actor and trigger, or "actor unknown — CloudTrail event not found">
EVIDENCE:
- describe-stacks: <quoted StackStatus, StackDriftStatus, LastDriftDetectionDateTime>
- describe-stack-resource-drifts: <quoted StackResourceDrift per drifted resource: ResourceDriftStatus, PropertyDifferences>
- CloudTrail: <quoted eventName, eventSource, eventTime, userIdentityarn for the out-of-band change, if found>
- Config timeline: <quoted configurationItem captureTime and diff for the drifted property, if available>
- describe-change-set (for the proposed fix): <quoted Action + Replacement for the resource being reset/imported>
ROOT_CAUSE_CATALOG: #<N>
RESOLUTION: <IMPORT | RESET_TO_DRIFT | REVERT_TO_TEMPLATE | REMOVE_FROM_TEMPLATE | ESCALATE_TO_OWNER>
REMEDIATION:
1. <exact CLI sequence — detect-stack-drift, import-resources, update-stack, or manual revert>
2. <verification command — describe-stack-resource-drifts until StackResourceDriftStatus: IN_SYNC>
3. <prevention step — IAM policy, CloudFormation Hook, or Conformance Pack rule>
FORBIDDEN output patterns
- NEVER start with "Let me analyze…" or "I'll investigate…" — the
INCIDENT line is the FIRST line, always. No conversational preamble.
- NEVER use lowercase verdict values — emit
ROOT_CAUSE_FOUND,
NEED_MORE_INFO, or ESCALATE.
- NEVER omit the per-resource
ResourceDriftStatus from EVIDENCE.
"The stack is drifted" is the symptom; the per-resource drift
classification is the diagnosis.
- NEVER recommend
update-stack to reset drift on a resource whose
drifted property is in the immutable-property list without
explicitly warning that the update will trigger Replacement.
- NEVER declare
ROOT_CAUSE_FOUND without naming the out-of-band
actor (or stating that the CloudTrail event was not found and the
actor is unknown).
Process — Diagnostic decision tree (apply in order)
Step 0: Capture the drift signal
Gather these six pieces. Each downstream step branches on which is
present.
| Signal |
Source |
Why required |
| Stack name or ARN + region |
User-provided or aws cloudformation list-stacks |
All describe calls need this |
| StackDriftStatus + LastDriftDetectionDateTime |
aws cloudformation describe-stacks --stack-name <name> (or describe-stack-resource-drifts) |
Confirms drift exists; stale detection time means a re-run is needed |
| StackResourceDrift list |
describe-stack-resource-drifts --stack-name <name> |
The primary diagnostic surface — per-resource drift classification and PropertyDifferences |
| CloudTrail events for the drifted resources |
aws cloudtrail lookup-events --lookup-attributes AttributeKey=ResourceName,AttributeValue=<PhysicalResourceId> |
Identifies who changed the resource and when |
| AWS Config configurationItems for the resource |
aws configservice get-resource-config-history --resource-type <type> --resource-id <id> |
Forensic timeline of property-level changes |
| Recent ChangeSets and stack events |
describe-change-set, describe-stack-events |
Determines whether the divergence is drift or a failed update |
If the user has not provided the stack name or region, emit
VERDICT: NEED_MORE_INFO with the list-stacks discovery command and
the list of missing inputs (stack name/ARN, region, StackDriftStatus,
StackResourceDrift output).
Step 1: Run / refresh drift detection
Drift detection is asynchronous and may be stale. Always run a fresh
detection before diagnosing:
# Start a new drift detection run:
DETECTION_ID=$(aws cloudformation detect-stack-drift --stack-name <name> \
--query 'StackDriftDetectionId' --output text)
# Poll until complete:
aws cloudformation describe-stack-drift-detection-status \
--stack-drift-detection-id $DETECTION_ID \
--query '{status:DetectionStatus, drift:StackDriftStatus, detected:Timestamp}'
DetectionStatus transitions: DETECTION_IN_PROGRESS →
DETECTION_COMPLETE (or DETECTION_FAILED). A DETECTION_FAILED
status usually means one or more resource types do not support drift
detection — proceed with the resources that were checked and flag the
unsupported ones as NOT_CHECKED.
For nested stacks, drift detection now recurses into child stacks
(2024-2025 enhancement). Each child stack's drift must be examined
independently via describe-stack-resource-drifts --stack-name <child-stack-arn>.
For CDK stacks, run cdk drift <stack-name> (CDK v2.180+, 2025),
which compares the synthesized template to the deployed stack and
reports drift at the construct level.
Step 2: Classify each drift
aws cloudformation describe-stack-resource-drifts --stack-name <name> \
--query 'StackResourceDrifts[?ResourceDriftStatus!=`IN_SYNC`].{logical:LogicalResourceId,physical:PhysicalResourceId,type:ResourceType,status:ResourceDriftStatus,diffs:PropertyDifferences}' \
--output table
Map each non-IN_SYNC resource to a category:
ResourceDriftStatus |
Category |
Diagnostic step |
MODIFIED |
A. MODIFIED |
Step 3 — identify the changed property and actor |
DELETED |
B. DELETED |
Step 3 — identify when the resource was deleted and whether dependencies remain |
ADDITION |
C. ADDITION (only visible via resource-level import scan or Config) |
Step 3 — identify whether the resource should be imported or deleted |
NOT_CHECKED |
D. NOT_CHECKED |
Flag as hidden drift; recommend AWS Config rule for ongoing posture |
IN_SYNC |
Not drift |
Skip |
Precedence rule. When multiple resources are drifted, prioritise
the drift on resources whose properties are immutable (Step 4) — those
drifts will trigger Replacement on the next update, which is the most
dangerous outcome. Read-only drifts (e.g., tags) are lower priority.
Step 3: Forensic walk — who changed it and when?
For each drifted resource, identify the out-of-band actor and the
change time. This drives the resolution choice (intentional vs
accidental drift).
# CloudTrail lookup for the specific physical resource:
aws cloudtrail lookup-events \
--lookup-attributes AttributeKey=ResourceName,AttributeValue=<PhysicalResourceId> \
--start-time <LastDriftDetectionDateTime minus 30 days> \
--end-time <LastDriftDetectionDateTime> \
--query 'Events[?EventName!=`Describe*'].{event:EventName,source:EventSource,time:EventTime,user:Username,ip:CloudTrailEvent' \
--output table
# Config timeline for property-level forensic diff:
aws configservice get-resource-config-history \
--resource-type <ResourceType e.g. AWS::S3::Bucket> \
--resource-id <PhysicalResourceId> \
--limit 10 \
--query 'configurationItems[].{capture:captureTime,version:configurationStateId,arn:arn}'
If the CloudTrail event is found, the actor and intent are known. If
the event is older than the trail retention (default 90 days), the
actor is unknown and the operator must decide based on whether the
drifted value is desirable.
Step 4: Assess update impact — is the drifted property immutable?
For each PropertyDifference, determine whether the changed property
is one CloudFormation treats as immutable (requires Replacement):
| Resource |
Common immutable properties |
Drift impact on update |
AWS::S3::Bucket |
BucketName |
Update triggers Replacement — the bucket is recreated with a new name |
AWS::DynamoDB::Table |
TableName, KeySchema, AttributeDefinitions (for keys) |
Update triggers Replacement |
AWS::RDS::DBInstance |
DBInstanceIdentifier, AllocatedStorage (downgrade), Engine |
Update triggers Replacement or fails |
AWS::IAM::Role |
RoleName |
Update triggers Replacement |
AWS::EC2::Instance |
InstanceType (depends), ImageId, KeyName |
Update triggers Replacement |
AWS::Lambda::Function |
FunctionName, Runtime (some), PackageType |
Update triggers Replacement |
AWS::SQS::Queue |
QueueName |
Update triggers Replacement |
AWS::Logs::LogGroup |
LogGroupName |
Update triggers Replacement |
The authoritative test is the ChangeSet: create a no-op ChangeSet on
the stack with describe-change-set and inspect the Replacement
field for the drifted resource.
aws cloudformation create-change-set --stack-name <name> \
--change-set-name drift-impact-probe \
--change-set-type UPDATE \
--template-body file://current-template.yaml \
--capabilities CAPABILITY_IAM
aws cloudformation describe-change-set \
--stack-name <name> --change-set-name drift-impact-probe \
--query 'Changes[?ResourceChange.LogicalResourceId==`<drifted-logical-id>`].ResourceChange.{action:Action,replacement:Replacement,scope:Scope}'
If Replacement: True and the operator does not want the resource
replaced, the only safe resolution is REVERT_TO_TEMPLATE (manually
restore the original property value on the physical resource before
any update-stack).
Step 5: Choose resolution strategy
| Goal |
Resolution |
How |
| Accept the out-of-band change as the new template truth |
RESET_TO_DRIFT |
Update the template property to match the actual value, then create-change-set + execute-change-set. Next drift detection reports IN_SYNC. |
| Restore the resource to match the template (drift is wrong) |
REVERT_TO_TEMPLATE |
Manually edit the physical resource (console / CLI) to restore the template value. No stack update is required; drift detection next run reports IN_SYNC. |
| Bring an out-of-band resource under stack management |
IMPORT |
create-change-set with --change-set-type IMPORT and --resources-to-import JSON; the template declares the resource; CloudFormation maps the existing physical resource to the logical id without recreating it. |
| The drifted resource is no longer needed |
REMOVE_FROM_TEMPLATE |
Delete the resource from the template and update-stack. For physical resources that should persist, set DeletionPolicy: Retain. |
| The drift is owned by another team or requires approval |
ESCALATE_TO_OWNER |
Surface the CloudTrail actor and Config timeline; route to the resource owner. Do not self-serve a reset. |
Resource import flow (resources-to-import JSON + IMPORT change set) moved verbatim to references/diagnostic-commands.md.
Load on demand when emitting the import CLI sequence.
Step 6: Validate via ChangeSet before applying any fix
Before applying any resolution that touches the stack, validate with a
ChangeSet:
- For
RESET_TO_DRIFT: run create-change-set --change-set-type UPDATE with the updated template. Confirm the drifted resource
shows Action: Modify, Replacement: False (or explicitly True if
accepted).
- For
IMPORT: run create-change-set --change-set-type IMPORT
with the --resources-to-import payload. Confirm the imported
resource shows Action: Import and no other resources change.
- For
REVERT_TO_TEMPLATE: no stack update is needed — the
physical resource is reverted manually; drift detection next run
confirms IN_SYNC.
- Execute the ChangeSet only after it matches expectations.
Step 7: Decide — ROOT_CAUSE_FOUND vs NEED_MORE_INFO vs ESCALATE
- ROOT_CAUSE_FOUND. The walk identified a specific drift type
(MODIFIED / DELETED / ADDITION), the offending resource(s), and a
resolution strategy with the exact CLI sequence. Output REMEDIATION.
- NEED_MORE_INFO. The walk reached a step where the operator
cannot supply evidence (e.g., CloudTrail lookup requires elevated
read access, the stack name is unknown, or the physical resource
cannot be identified). Output the list of missing inputs.
- ESCALATE. The walk identifies drift owned by another team
(different AWS account, separate IAM owner), drift that requires
security or compliance approval (e.g., a bucket policy weakened
out-of-band), or drift on a resource type that CloudFormation
cannot import. Output the escalation target and the specific
request.
Step 8: Prevent recurrence
| Prevention mechanism |
Scope |
How |
| IAM policy to restrict direct changes |
Per principal |
Attach a deny policy on the underlying service API (e.g., s3:PutBucketPolicy for a bucket managed by CFN) for all principals except the CloudFormation execution role. Use a Condition keyed to aws:CalledViaFirst: cloudformation.amazonaws.com to allow the change only when made via CloudFormation. |
| Service Control Policy (org-level) |
Account / OU |
SCP that denies direct resource mutations on CFN-managed resource types except via CloudFormation. |
| CloudFormation Hooks |
Stack-level, pre-deployment |
Author a Hook that validates resource configuration at CREATE_PRE_DEPLOYMENT / UPDATE_PRE_DEPLOYMENT. Hooks do not prevent out-of-band drift directly, but they enforce compliance on the next stack update. |
| AWS Config Conformance Pack |
Account / org |
Deploy a conformance pack with cloudformation-stack-drift-detection-check and custom rules that alert on StackDriftStatus: DRIFTED. Combine with an SNS topic and Lambda remediation for auto-detection. |
| CloudTrail alarm on direct mutations |
Per resource |
CloudWatch metric filter on CloudTrail for direct API calls on CFN-managed resources, alarming on out-of-band changes within minutes. |
IAM aws:CalledViaFirst prevention policy deep dive (full JSON) moved verbatim to references/advanced-patterns.md.
Load on demand when authoring drift-prevention IAM policy.
Output format
INCIDENT: <stack name or ARN> in <region> — StackDriftStatus <status>, <N> drifted resource(s)
VERDICT: ROOT_CAUSE_FOUND | NEED_MORE_INFO | ESCALATE
ROOT_CAUSE: <MODIFIED | DELETED | ADDITION> on <LogicalResourceId (PhysicalResourceId)> — <actor and trigger>
EVIDENCE:
- describe-stacks: <StackStatus, StackDriftStatus, LastDriftDetectionDateTime>
- describe-stack-resource-drifts: <ResourceDriftStatus + PropertyDifferences per resource>
- CloudTrail: <eventName, eventSource, eventTime, userIdentityarn>
- Config timeline: <configurationItem captureTime + diff>
- describe-change-set: <Action + Replacement for the proposed fix>
ROOT_CAUSE_CATALOG: #<N>
RESOLUTION: <IMPORT | RESET_TO_DRIFT | REVERT_TO_TEMPLATE | REMOVE_FROM_TEMPLATE | ESCALATE_TO_OWNER>
REMEDIATION:
1. <exact CLI sequence>
2. <verification — describe-stack-resource-drifts until IN_SYNC>
3. <prevention — IAM policy, CloudFormation Hook, or Conformance Pack>
Worked example — MODIFIED drift on S3 bucket policy (RESET_TO_DRIFT)
INCIDENT: logging-stack in us-east-1 — StackDriftStatus DRIFTED, 1
drifted resource (LogsBucket)
VERDICT: ROOT_CAUSE_FOUND
ROOT_CAUSE: MODIFIED on LogsBucket (logging-stack-logsbucket-abc) —
the bucket policy was edited out-of-band on 2026-08-04 by an
operator adding a cross-account PutObject grant from account
111122223333, diverging from the template policy
EVIDENCE:
- describe-stacks: StackStatus CREATE_COMPLETE, StackDriftStatus
DRIFTED, LastDriftDetectionDateTime 2026-08-05T09:14:22Z
- describe-stack-resource-drifts: LogsBucket
ResourceDriftStatus MODIFIED with 1 PropertyDifference on
BucketPolicy.Document.Statement[0].Principal from
{"Service":"logging.us-east-1.amazonaws.com"} to
{"AWS":"arn:aws:iam::111122223333:root"}
- CloudTrail: PutBucketPolicy on s3.amazonaws.com at
2026-08-04T22:11:48Z by arn:aws:iam::111122223333:user/dev-alice
from source IP 10.42.1.5
- Config timeline: configurationItem captured 2026-08-04T22:11:49Z
showing the policy Principal change
- describe-change-set (drift-impact-probe): LogsBucket Action
Modify, Replacement False, Scope [Properties] — the policy drift
does NOT require Replacement
ROOT_CAUSE_CATALOG: #1 (out-of-band modification of CFN-managed resource)
RESOLUTION: RESET_TO_DRIFT
REMEDIATION:
1. The change appears intentional (the cross-account grant is a
legitimate logging use case). Accept the drift by updating the
template to match the actual policy, then create and execute a
ChangeSet:
aws cloudformation create-change-set \
--stack-name logging-stack \
--change-set-name accept-bucket-policy-drift \
--change-set-type UPDATE \
--template-body file://template-with-updated-policy.yaml \
--capabilities CAPABILITY_IAM
aws cloudformation describe-change-set \
--stack-name logging-stack \
--change-set-name accept-bucket-policy-drift
Confirm LogsBucket Action Modify, Replacement False. Then:
aws cloudformation execute-change-set \
--stack-name logging-stack --change-set-name accept-bucket-policy-drift
2. Verify drift is resolved:
DETECTION_ID=$(aws cloudformation detect-stack-drift \
--stack-name logging-stack --query 'StackDriftDetectionId' --output text)
aws cloudformation describe-stack-drift-detection-status \
--stack-drift-detection-id $DETECTION_ID
Expect StackDriftStatus IN_SYNC after DetectionStatus DETECTION_COMPLETE.
3. Prevent recurrence — attach a deny policy on
s3:PutBucketPolicy scoped to this bucket, conditioned on
aws:CalledViaFirst != cloudformation.amazonaws.com, so future
edits are made only through the stack. Alternative: deploy a
Conformance Pack with cloudformation-stack-drift-detection-check
alarming to the SRE SNS topic.
Expert edge cases
Expert edge cases (10 non-obvious drift behaviours) moved verbatim to references/advanced-patterns.md.
Load on demand when the drift signal does not match the obvious pattern.
Expert heuristic — "Read the per-resource ResourceDriftStatus, not the stack-level StackDriftStatus"
Expert heuristic — per-resource ResourceDriftStatus lookup table moved verbatim to references/advanced-patterns.md.
Load on demand when classifying per-resource findings into resolutions.
Anti-Patterns — NEVER
- NEVER treat
StackDriftStatus: DRIFTED as the root cause. It
is the symptom. The per-resource ResourceDriftStatus and
PropertyDifferences are the diagnosis.
- NEVER recommend
update-stack to reset drift on a resource
whose drifted property is immutable without explicitly warning that
the update triggers Replacement. Always probe with a ChangeSet
first.
- NEVER recommend
import-resources without verifying that the
template properties match the actual physical resource exactly.
Mismatch causes IMPORT_FAILED.
- NEVER declare
ROOT_CAUSE_FOUND without naming the out-of-band
actor (or explicitly stating that the CloudTrail event was not
found and the actor is unknown).
- NEVER rely on a stale
StackDriftStatus from the console.
Always run detect-stack-drift fresh before diagnosing, then poll
describe-stack-drift-detection-status to confirm completion.
- NEVER assume
IN_SYNC on a stack with NOT_CHECKED resources
means no drift exists. Drift detection does not cover all resource
types; use AWS Config for full posture.
- NEVER treat
DeletionPolicy: Retain resources as drifted when
they persist after stack delete. They are intentionally retained;
track them via AWS Config separately.
- NEVER run
update-stack blind on a drifted stack. Always
create and review a ChangeSet first, inspecting Replacement for
every drifted resource.
- NEVER recommend a
Deny IAM policy on the underlying service
API without the aws:CalledViaFirst: cloudformation.amazonaws.com
condition — an unconditional deny breaks CloudFormation itself.
- NEVER assume
cdk drift output maps 1:1 to CloudFormation
resource drift. Always cross-reference
describe-stack-resource-drifts for resource-level detail.
- NEVER assume a nested stack's parent drift reflects the root
cause. Drill into the child stack — the parent's
AWS::CloudFormation::Stack resource only carries the child's
status.
- NEVER conclude drift resolution without re-running
detect-stack-drift and confirming StackResourceDriftStatus: IN_SYNC on every previously-drifted resource.
Recent AWS features (2024-2026)
Recent AWS features (nested-stack drift, resource import, cdk drift, IaC Generator, Hooks) moved verbatim to references/advanced-patterns.md.
Load on demand when confirming feature availability or vintage.
References
See references/drift-types-and-resolution.md for the full
per-drift-type decision matrix with worked examples for each
resolution strategy, and references/diagnostic-commands.md for the
canonical command script for drift detection, forensic walk, and
remediation.
References (load on demand)
- references/drift-types-and-resolution.md — full per-drift-type decision matrix and resolution playbook.
- references/diagnostic-commands.md — canonical command script; now also holds the Step 5 resource-import flow moved from SKILL.md.
- references/advanced-patterns.md — expert edge-case catalog, Step 8 IAM prevention deep dive, per-resource heuristic, and recent AWS features moved from SKILL.md.
Domain
AWS CloudOps / DevTools — Infrastructure-as-Code Configuration
Compliance.
AWS documentation
1---2name: cloudformation-drift-troubleshooter3description: 'Diagnoses AWS CloudFormation stack drift — resources whose actual configuration diverged from the template because they were changed, deleted, or added outside CloudFormation. Walks detect-stack-drift, describe-stack-drift-detection-status, and describe-stack-resource-drifts to classify each drift as MODIFIED (property changed outside CFN), DELETED (resource deleted outside CFN), or ADDITION (new resource not in stack). Maps drift impact on stack updates and recommends a resolution strategy: import existing resources (import-resources), drift reset (update to match drift), or revert the resource to match template. Covers drift prevention via IAM policy with aws:CalledViaFirst, CloudFormation Hooks, and Conformance Packs. Handles nested stack drift and CDK drift. Emits ROOT_CAUSE_FOUND | NEED_MORE_INFO | ESCALATE. Use when a stack reports DRIFTED, an UPDATE_FAILED cites drift as the cause, an operator needs to import out-of-band resources, or a compliance pack flags stack drift.'4license: Apache-2.05compatibility: Agent runtime that reads SKILL.md (Claude Code, Cursor, Windsurf, Codex, Gemini). Offline diagnosis works on supplied describe-stack-resource-drifts JSON. Live-account diagnosis uses aws cloudformation detect-stack-drift, describe-stack-drift-detection-status, describe-stack-resource-drifts, describe-stack-resources, describe-change-set, aws iam simulate-principal-policy, and aws configservice get-resource-config-history for forensic property-level timeline (AWS CLI v2, SSO or key-based...6metadata:7 source: https://skillmd.com/skills/jhkchan/cloudformation-drift-troubleshooter8 domain: aws-cloudops9 complexity: high10 requires_llm: 'true'11 phase: '2'12 supports_pipeline: 'true'13 entry_point: 'false'14 family: DevTools15 task_type: troubleshoot16 skill_class: capability17 lifecycle_status: active18 verdict_shape: ROOT_CAUSE_FOUND | NEED_MORE_INFO | ESCALATE19 when_to_use: Diagnosing why a stack reports StackDriftStatus DRIFTED, why an UPDATE_FAILED cites drift as the cause, why a resource was modified or deleted outside CloudFormation, how to classify per-resource drift (MODIFIED / DELETED / ADDITION), how to resolve drift via import / reset / revert, how to prevent recurrence via IAM policy or CloudFormation Hooks, or how to walk nested-stack drift and CDK drift.20 when_not_to_use: Stack lifecycle failures unrelated to drift (use cloudformation-stack-troubleshooter for CREATE_FAILED, UPDATE_FAILED with Replacement, DELETE_FAILED, ROLLBACK_COMPLETE, UPDATE_ROLLBACK_FAILED). IaC generation from existing resources (use the IaC Generator skill). Pure CloudFormation Hooks authoring (use the Hooks authoring reference). CDK errors that are not drift-related (use the CDK troubleshooter).21 activation_triggers: CloudFormation drift, stack drift, StackDriftStatus DRIFTED, ResourceDriftStatus MODIFIED, ResourceDriftStatus DELETED, ResourceDriftStatus ADDITION, describe-stack-resource-drifts, detect-stack-drift, resource modified outside CloudFormation, resource deleted outside CloudFormation, import existing resources into stack, drift reset, CloudFormation Hooks, CDK drift, nested stack drift, Conformance Pack drift22 invocation_schema: 'Input: either (a) a symptom description (stack name or ARN, region, observed StackDriftStatus, the list of StackResourceDrifts with their ResourceDriftStatus and PropertyDifferences), OR (b) a live-account scenario where the agent runs aws cloudformation detect-stack-drift / describe-stack-drift-detection-status / describe-stack-resource-drifts and aws configservice get-resource-config-history to gather evidence. Output: a deterministic INCIDENT / VERDICT / ROOT_CAUSE / EVIDENCE / ROOT_CAUSE_CATALOG / REMEDIATION block where VERDICT ∈ {ROOT_CAUSE_FOUND, NEED_MORE_INFO, ESCALATE} and ROOT_CAUSE names the drift type (MODIFIED / DELETED / ADDITION) and the offending resource(s), with a resolution strategy chosen from {IMPORT, RESET_TO_DRIFT, REVERT_TO_TEMPLATE, ESCALATE_TO_OWNER}.'23 version: 0.1.024 author: Jacky Chan — AWS Community Builder25 keywords: CloudFormation, drift, detect-stack-drift, describe-stack-resource-drifts, StackDriftStatus, DRIFTED, MODIFIED, DELETED, ADDITION, resource import, import-resources, drift reset, out-of-band change, CloudFormation Hooks, Conformance Pack, nested stack drift, CDK drift, UPDATE_FAILED26 tags: cloudformation, devtools, troubleshoot, drift, resource-import, guardrails27---2829# CloudFormation Drift Troubleshooter3031## Activation3233Activate this skill when the user reports CloudFormation drift. Trigger34phrases: "CloudFormation drift", "stack drift",35"StackDriftStatus DRIFTED", "ResourceDriftStatus MODIFIED",36"ResourceDriftStatus DELETED", "ResourceDriftStatus ADDITION",37"describe-stack-resource-drifts", "detect-stack-drift", "resource38modified outside CloudFormation", "resource deleted outside39CloudFormation", "import existing resources into stack", "drift reset",40"CloudFormation Hooks", "CDK drift", "nested stack drift".4142## Mindset4344**One-line takeaway:** CloudFormation drift is the gap between the45template-of-record and the actual resource state. The diagnostic surface46is `describe-stack-resource-drifts`, which classifies each resource as47`MODIFIED`, `DELETED`, `ADDITION`, or `IN_SYNC`. The job of this skill48is to (1) confirm drift exists, (2) classify each drift by type and49severity, (3) identify the out-of-band actor and trigger, (4) choose a50resolution strategy (import, reset to drift, revert to template), and51(5) prevent recurrence.5253Three facts make drift troubleshooting different from generic stack54failure triage:5556- **Drift is not an error — it is a state.** `StackDriftStatus: DRIFTED`57 does not block the stack from being read; it warns that the next58 update may not behave as the operator expects. Many stacks run DRIFTED59 for months without incident. The actionable question is "which60 property diverged, who changed it, and what happens if I update now?"6162- **Each drift type has a different resolution.** A `MODIFIED` drift63 can be reset by accepting the out-of-band value into the template64 (drift reset) or by reverting the resource to match the template.65 A `DELETED` drift usually means the resource was removed manually66 and must be recreated or imported-as-gone. An `ADDITION` drift67 requires the operator to decide whether to bring the new resource68 under stack management (import) or delete the out-of-band resource.6970- **Drift on immutable properties is the dangerous case.** If a drifted71 property is one CloudFormation treats as requiring Replacement (e.g.,72 an RDS DBInstanceIdentifier, a DynamoDB KeySchema, an S3 bucket's73 BucketName), the next update will trigger resource replacement —74 often the opposite of what the operator wants. Always cross-reference75 each `PropertyDifference` against the resource's immutable-property76 list before recommending `update-stack`.7778## Quick reference — drift type to resolution7980| Drift type | What it means | Resolution options | Risk |81|---|---|---|---|82| `MODIFIED` (property changed outside CFN) | A property on an existing stack resource was edited via console / SDK / CLI, not via stack update | (a) Drift reset — update template to match actual, then `update-stack`; (b) Revert — manually set resource back to template value; (c) Import-as-truth — `import-resources` with the new template | If the drifted property is immutable, `update-stack` triggers Replacement |83| `DELETED` (resource deleted outside CFN) | The physical resource backing a stack resource was deleted via console / SDK / CLI | (a) Recreate — `update-stack` will recreate the missing resource; (b) Remove from template if the resource is no longer needed; (c) Mark as `DeletionPolicy: Retain` if intentional | Stack update will attempt to recreate — may fail if dependencies are gone |84| `ADDITION` (new resource not in stack) | A new physical resource exists in the account but is not managed by the stack (visible via resource-level import scan or Config) | (a) Import — `import-resources` to bring under stack management; (b) Delete the out-of-band resource; (c) Ignore if intentionally unmanaged | Out-of-band resources are invisible to stack delete — they persist silently |85| `NOT_CHECKED` | Drift detection has not run for this resource (e.g., a resource type that does not support drift detection) | Run `detect-stack-drift`; for unsupported types, use AWS Config rules for posture | Hidden drift — the stack reports `IN_SYNC` but the resource may have diverged |86| Drift on `DeletionPolicy: Retain` resource | The retained resource drifts but CloudFormation does not reconcile it on stack delete | Track separately; consider `UpdateReplacePolicy: Delete` if drift resets are desired | Resource persists after stack delete regardless of drift |8788## Quick navigation8990- **Step 0** — Capture the drift signal (stack name/ARN, region,91 StackDriftStatus, time of last detection, trigger source).92- **Step 1** — Run / refresh drift detection93 (`detect-stack-drift` then poll94 `describe-stack-drift-detection-status`).95- **Step 2** — Read `describe-stack-resource-drifts` and classify each96 drift (MODIFIED / DELETED / ADDITION).97- **Step 3** — Forensic walk: who changed it and when? (CloudTrail,98 Config timeline).99- **Step 4** — Assess update impact: for each `PropertyDifference`,100 determine if the property is immutable (Replacement required).101- **Step 5** — Choose resolution: IMPORT, RESET_TO_DRIFT,102 REVERT_TO_TEMPLATE, REMOVE_FROM_TEMPLATE.103- **Step 6** — Validate via ChangeSet (or `create-change-set` for104 resource import) before applying.105- **Step 7** — Decide VERDICT (ROOT_CAUSE_FOUND / NEED_MORE_INFO /106 ESCALATE).107- **Step 8** — Prevent recurrence (IAM policy, CloudFormation Hooks,108 Conformance Pack).109110## STRICT output contract111112Every response MUST begin with this block — no preamble, no113conversational opening:114115```text116INCIDENT: <stack name or ARN> in <region> — StackDriftStatus <status>, <N> drifted resource(s)117VERDICT: ROOT_CAUSE_FOUND | NEED_MORE_INFO | ESCALATE118ROOT_CAUSE: <MODIFIED | DELETED | ADDITION> on <LogicalResourceId (PhysicalResourceId)> — <one-sentence identifying the out-of-band actor and trigger, or "actor unknown — CloudTrail event not found">119EVIDENCE:120 - describe-stacks: <quoted StackStatus, StackDriftStatus, LastDriftDetectionDateTime>121 - describe-stack-resource-drifts: <quoted StackResourceDrift per drifted resource: ResourceDriftStatus, PropertyDifferences>122 - CloudTrail: <quoted eventName, eventSource, eventTime, userIdentityarn for the out-of-band change, if found>123 - Config timeline: <quoted configurationItem captureTime and diff for the drifted property, if available>124 - describe-change-set (for the proposed fix): <quoted Action + Replacement for the resource being reset/imported>125ROOT_CAUSE_CATALOG: #<N>126RESOLUTION: <IMPORT | RESET_TO_DRIFT | REVERT_TO_TEMPLATE | REMOVE_FROM_TEMPLATE | ESCALATE_TO_OWNER>127REMEDIATION:128 1. <exact CLI sequence — detect-stack-drift, import-resources, update-stack, or manual revert>129 2. <verification command — describe-stack-resource-drifts until StackResourceDriftStatus: IN_SYNC>130 3. <prevention step — IAM policy, CloudFormation Hook, or Conformance Pack rule>131```132133### FORBIDDEN output patterns134135- NEVER start with "Let me analyze…" or "I'll investigate…" — the136 INCIDENT line is the FIRST line, always. No conversational preamble.137- NEVER use lowercase verdict values — emit `ROOT_CAUSE_FOUND`,138 `NEED_MORE_INFO`, or `ESCALATE`.139- NEVER omit the per-resource `ResourceDriftStatus` from EVIDENCE.140 "The stack is drifted" is the symptom; the per-resource drift141 classification is the diagnosis.142- NEVER recommend `update-stack` to reset drift on a resource whose143 drifted property is in the immutable-property list without144 explicitly warning that the update will trigger Replacement.145- NEVER declare `ROOT_CAUSE_FOUND` without naming the out-of-band146 actor (or stating that the CloudTrail event was not found and the147 actor is unknown).148149## Process — Diagnostic decision tree (apply in order)150151### Step 0: Capture the drift signal152153Gather these six pieces. Each downstream step branches on which is154present.155156| Signal | Source | Why required |157|---|---|---|158| **Stack name or ARN + region** | User-provided or `aws cloudformation list-stacks` | All describe calls need this |159| **StackDriftStatus + LastDriftDetectionDateTime** | `aws cloudformation describe-stacks --stack-name <name>` (or `describe-stack-resource-drifts`) | Confirms drift exists; stale detection time means a re-run is needed |160| **StackResourceDrift list** | `describe-stack-resource-drifts --stack-name <name>` | The primary diagnostic surface — per-resource drift classification and PropertyDifferences |161| **CloudTrail events for the drifted resources** | `aws cloudtrail lookup-events --lookup-attributes AttributeKey=ResourceName,AttributeValue=<PhysicalResourceId>` | Identifies who changed the resource and when |162| **AWS Config configurationItems for the resource** | `aws configservice get-resource-config-history --resource-type <type> --resource-id <id>` | Forensic timeline of property-level changes |163| **Recent ChangeSets and stack events** | `describe-change-set`, `describe-stack-events` | Determines whether the divergence is drift or a failed update |164165If the user has not provided the stack name or region, emit166`VERDICT: NEED_MORE_INFO` with the `list-stacks` discovery command and167the list of missing inputs (stack name/ARN, region, StackDriftStatus,168StackResourceDrift output).169170### Step 1: Run / refresh drift detection171172Drift detection is asynchronous and may be stale. Always run a fresh173detection before diagnosing:174175```bash176# Start a new drift detection run:177DETECTION_ID=$(aws cloudformation detect-stack-drift --stack-name <name> \178 --query 'StackDriftDetectionId' --output text)179180# Poll until complete:181aws cloudformation describe-stack-drift-detection-status \182 --stack-drift-detection-id $DETECTION_ID \183 --query '{status:DetectionStatus, drift:StackDriftStatus, detected:Timestamp}'184```185186`DetectionStatus` transitions: `DETECTION_IN_PROGRESS` →187`DETECTION_COMPLETE` (or `DETECTION_FAILED`). A `DETECTION_FAILED`188status usually means one or more resource types do not support drift189detection — proceed with the resources that were checked and flag the190unsupported ones as `NOT_CHECKED`.191192For **nested stacks**, drift detection now recurses into child stacks193(2024-2025 enhancement). Each child stack's drift must be examined194independently via `describe-stack-resource-drifts --stack-name195<child-stack-arn>`.196197For **CDK stacks**, run `cdk drift <stack-name>` (CDK v2.180+, 2025),198which compares the synthesized template to the deployed stack and199reports drift at the construct level.200201### Step 2: Classify each drift202203```bash204aws cloudformation describe-stack-resource-drifts --stack-name <name> \205 --query 'StackResourceDrifts[?ResourceDriftStatus!=`IN_SYNC`].{logical:LogicalResourceId,physical:PhysicalResourceId,type:ResourceType,status:ResourceDriftStatus,diffs:PropertyDifferences}' \206 --output table207```208209Map each non-`IN_SYNC` resource to a category:210211| `ResourceDriftStatus` | Category | Diagnostic step |212|---|---|---|213| `MODIFIED` | **A. MODIFIED** | Step 3 — identify the changed property and actor |214| `DELETED` | **B. DELETED** | Step 3 — identify when the resource was deleted and whether dependencies remain |215| `ADDITION` | **C. ADDITION** (only visible via resource-level import scan or Config) | Step 3 — identify whether the resource should be imported or deleted |216| `NOT_CHECKED` | **D. NOT_CHECKED** | Flag as hidden drift; recommend AWS Config rule for ongoing posture |217| `IN_SYNC` | Not drift | Skip |218219**Precedence rule.** When multiple resources are drifted, prioritise220the drift on resources whose properties are immutable (Step 4) — those221drifts will trigger Replacement on the next update, which is the most222dangerous outcome. Read-only drifts (e.g., tags) are lower priority.223224### Step 3: Forensic walk — who changed it and when?225226For each drifted resource, identify the out-of-band actor and the227change time. This drives the resolution choice (intentional vs228accidental drift).229230```bash231# CloudTrail lookup for the specific physical resource:232aws cloudtrail lookup-events \233 --lookup-attributes AttributeKey=ResourceName,AttributeValue=<PhysicalResourceId> \234 --start-time <LastDriftDetectionDateTime minus 30 days> \235 --end-time <LastDriftDetectionDateTime> \236 --query 'Events[?EventName!=`Describe*'].{event:EventName,source:EventSource,time:EventTime,user:Username,ip:CloudTrailEvent' \237 --output table238239# Config timeline for property-level forensic diff:240aws configservice get-resource-config-history \241 --resource-type <ResourceType e.g. AWS::S3::Bucket> \242 --resource-id <PhysicalResourceId> \243 --limit 10 \244 --query 'configurationItems[].{capture:captureTime,version:configurationStateId,arn:arn}'245```246247If the CloudTrail event is found, the actor and intent are known. If248the event is older than the trail retention (default 90 days), the249actor is unknown and the operator must decide based on whether the250drifted value is desirable.251252### Step 4: Assess update impact — is the drifted property immutable?253254For each `PropertyDifference`, determine whether the changed property255is one CloudFormation treats as immutable (requires Replacement):256257| Resource | Common immutable properties | Drift impact on update |258|---|---|---|259| `AWS::S3::Bucket` | `BucketName` | Update triggers Replacement — the bucket is recreated with a new name |260| `AWS::DynamoDB::Table` | `TableName`, `KeySchema`, `AttributeDefinitions` (for keys) | Update triggers Replacement |261| `AWS::RDS::DBInstance` | `DBInstanceIdentifier`, `AllocatedStorage` (downgrade), `Engine` | Update triggers Replacement or fails |262| `AWS::IAM::Role` | `RoleName` | Update triggers Replacement |263| `AWS::EC2::Instance` | `InstanceType` (depends), `ImageId`, `KeyName` | Update triggers Replacement |264| `AWS::Lambda::Function` | `FunctionName`, `Runtime` (some), `PackageType` | Update triggers Replacement |265| `AWS::SQS::Queue` | `QueueName` | Update triggers Replacement |266| `AWS::Logs::LogGroup` | `LogGroupName` | Update triggers Replacement |267268The authoritative test is the ChangeSet: create a no-op ChangeSet on269the stack with `describe-change-set` and inspect the `Replacement`270field for the drifted resource.271272```bash273aws cloudformation create-change-set --stack-name <name> \274 --change-set-name drift-impact-probe \275 --change-set-type UPDATE \276 --template-body file://current-template.yaml \277 --capabilities CAPABILITY_IAM278279aws cloudformation describe-change-set \280 --stack-name <name> --change-set-name drift-impact-probe \281 --query 'Changes[?ResourceChange.LogicalResourceId==`<drifted-logical-id>`].ResourceChange.{action:Action,replacement:Replacement,scope:Scope}'282```283284If `Replacement: True` and the operator does not want the resource285replaced, the only safe resolution is `REVERT_TO_TEMPLATE` (manually286restore the original property value on the physical resource before287any `update-stack`).288289### Step 5: Choose resolution strategy290291| Goal | Resolution | How |292|---|---|---|293| Accept the out-of-band change as the new template truth | `RESET_TO_DRIFT` | Update the template property to match the actual value, then `create-change-set` + `execute-change-set`. Next drift detection reports `IN_SYNC`. |294| Restore the resource to match the template (drift is wrong) | `REVERT_TO_TEMPLATE` | Manually edit the physical resource (console / CLI) to restore the template value. No stack update is required; drift detection next run reports `IN_SYNC`. |295| Bring an out-of-band resource under stack management | `IMPORT` | `create-change-set` with `--change-set-type IMPORT` and `--resources-to-import` JSON; the template declares the resource; CloudFormation maps the existing physical resource to the logical id without recreating it. |296| The drifted resource is no longer needed | `REMOVE_FROM_TEMPLATE` | Delete the resource from the template and `update-stack`. For physical resources that should persist, set `DeletionPolicy: Retain`. |297| The drift is owned by another team or requires approval | `ESCALATE_TO_OWNER` | Surface the CloudTrail actor and Config timeline; route to the resource owner. Do not self-serve a reset. |298299Resource import flow (resources-to-import JSON + IMPORT change set) moved verbatim to [references/diagnostic-commands.md](references/diagnostic-commands.md).300Load on demand when emitting the import CLI sequence.301302### Step 6: Validate via ChangeSet before applying any fix303304Before applying any resolution that touches the stack, validate with a305ChangeSet:3063071. **For `RESET_TO_DRIFT`:** run `create-change-set --change-set-type308 UPDATE` with the updated template. Confirm the drifted resource309 shows `Action: Modify`, `Replacement: False` (or explicitly True if310 accepted).3112. **For `IMPORT`:** run `create-change-set --change-set-type IMPORT`312 with the `--resources-to-import` payload. Confirm the imported313 resource shows `Action: Import` and no other resources change.3143. **For `REVERT_TO_TEMPLATE`:** no stack update is needed — the315 physical resource is reverted manually; drift detection next run316 confirms `IN_SYNC`.3174. **Execute** the ChangeSet only after it matches expectations.318319### Step 7: Decide — ROOT_CAUSE_FOUND vs NEED_MORE_INFO vs ESCALATE320321- **ROOT_CAUSE_FOUND.** The walk identified a specific drift type322 (MODIFIED / DELETED / ADDITION), the offending resource(s), and a323 resolution strategy with the exact CLI sequence. Output REMEDIATION.324- **NEED_MORE_INFO.** The walk reached a step where the operator325 cannot supply evidence (e.g., CloudTrail lookup requires elevated326 read access, the stack name is unknown, or the physical resource327 cannot be identified). Output the list of missing inputs.328- **ESCALATE.** The walk identifies drift owned by another team329 (different AWS account, separate IAM owner), drift that requires330 security or compliance approval (e.g., a bucket policy weakened331 out-of-band), or drift on a resource type that CloudFormation332 cannot import. Output the escalation target and the specific333 request.334335### Step 8: Prevent recurrence336337| Prevention mechanism | Scope | How |338|---|---|---|339| **IAM policy to restrict direct changes** | Per principal | Attach a deny policy on the underlying service API (e.g., `s3:PutBucketPolicy` for a bucket managed by CFN) for all principals except the CloudFormation execution role. Use a `Condition` keyed to `aws:CalledViaFirst: cloudformation.amazonaws.com` to allow the change only when made via CloudFormation. |340| **Service Control Policy (org-level)** | Account / OU | SCP that denies direct resource mutations on CFN-managed resource types except via CloudFormation. |341| **CloudFormation Hooks** | Stack-level, pre-deployment | Author a Hook that validates resource configuration at `CREATE_PRE_DEPLOYMENT` / `UPDATE_PRE_DEPLOYMENT`. Hooks do not prevent out-of-band drift directly, but they enforce compliance on the next stack update. |342| **AWS Config Conformance Pack** | Account / org | Deploy a conformance pack with `cloudformation-stack-drift-detection-check` and custom rules that alert on `StackDriftStatus: DRIFTED`. Combine with an SNS topic and Lambda remediation for auto-detection. |343| **CloudTrail alarm on direct mutations** | Per resource | CloudWatch metric filter on CloudTrail for direct API calls on CFN-managed resources, alarming on out-of-band changes within minutes. |344345IAM `aws:CalledViaFirst` prevention policy deep dive (full JSON) moved verbatim to [references/advanced-patterns.md](references/advanced-patterns.md).346Load on demand when authoring drift-prevention IAM policy.347348## Output format349350```text351INCIDENT: <stack name or ARN> in <region> — StackDriftStatus <status>, <N> drifted resource(s)352VERDICT: ROOT_CAUSE_FOUND | NEED_MORE_INFO | ESCALATE353ROOT_CAUSE: <MODIFIED | DELETED | ADDITION> on <LogicalResourceId (PhysicalResourceId)> — <actor and trigger>354EVIDENCE:355 - describe-stacks: <StackStatus, StackDriftStatus, LastDriftDetectionDateTime>356 - describe-stack-resource-drifts: <ResourceDriftStatus + PropertyDifferences per resource>357 - CloudTrail: <eventName, eventSource, eventTime, userIdentityarn>358 - Config timeline: <configurationItem captureTime + diff>359 - describe-change-set: <Action + Replacement for the proposed fix>360ROOT_CAUSE_CATALOG: #<N>361RESOLUTION: <IMPORT | RESET_TO_DRIFT | REVERT_TO_TEMPLATE | REMOVE_FROM_TEMPLATE | ESCALATE_TO_OWNER>362REMEDIATION:363 1. <exact CLI sequence>364 2. <verification — describe-stack-resource-drifts until IN_SYNC>365 3. <prevention — IAM policy, CloudFormation Hook, or Conformance Pack>366```367368### Worked example — MODIFIED drift on S3 bucket policy (RESET_TO_DRIFT)369370```text371INCIDENT: logging-stack in us-east-1 — StackDriftStatus DRIFTED, 1372drifted resource (LogsBucket)373VERDICT: ROOT_CAUSE_FOUND374ROOT_CAUSE: MODIFIED on LogsBucket (logging-stack-logsbucket-abc) —375the bucket policy was edited out-of-band on 2026-08-04 by an376operator adding a cross-account PutObject grant from account377111122223333, diverging from the template policy378EVIDENCE:379 - describe-stacks: StackStatus CREATE_COMPLETE, StackDriftStatus380 DRIFTED, LastDriftDetectionDateTime 2026-08-05T09:14:22Z381 - describe-stack-resource-drifts: LogsBucket382 ResourceDriftStatus MODIFIED with 1 PropertyDifference on383 BucketPolicy.Document.Statement[0].Principal from384 {"Service":"logging.us-east-1.amazonaws.com"} to385 {"AWS":"arn:aws:iam::111122223333:root"}386 - CloudTrail: PutBucketPolicy on s3.amazonaws.com at387 2026-08-04T22:11:48Z by arn:aws:iam::111122223333:user/dev-alice388 from source IP 10.42.1.5389 - Config timeline: configurationItem captured 2026-08-04T22:11:49Z390 showing the policy Principal change391 - describe-change-set (drift-impact-probe): LogsBucket Action392 Modify, Replacement False, Scope [Properties] — the policy drift393 does NOT require Replacement394ROOT_CAUSE_CATALOG: #1 (out-of-band modification of CFN-managed resource)395RESOLUTION: RESET_TO_DRIFT396REMEDIATION:397 1. The change appears intentional (the cross-account grant is a398 legitimate logging use case). Accept the drift by updating the399 template to match the actual policy, then create and execute a400 ChangeSet:401 aws cloudformation create-change-set \402 --stack-name logging-stack \403 --change-set-name accept-bucket-policy-drift \404 --change-set-type UPDATE \405 --template-body file://template-with-updated-policy.yaml \406 --capabilities CAPABILITY_IAM407 aws cloudformation describe-change-set \408 --stack-name logging-stack \409 --change-set-name accept-bucket-policy-drift410 Confirm LogsBucket Action Modify, Replacement False. Then:411 aws cloudformation execute-change-set \412 --stack-name logging-stack --change-set-name accept-bucket-policy-drift413 2. Verify drift is resolved:414 DETECTION_ID=$(aws cloudformation detect-stack-drift \415 --stack-name logging-stack --query 'StackDriftDetectionId' --output text)416 aws cloudformation describe-stack-drift-detection-status \417 --stack-drift-detection-id $DETECTION_ID418 Expect StackDriftStatus IN_SYNC after DetectionStatus DETECTION_COMPLETE.419 3. Prevent recurrence — attach a deny policy on420 s3:PutBucketPolicy scoped to this bucket, conditioned on421 aws:CalledViaFirst != cloudformation.amazonaws.com, so future422 edits are made only through the stack. Alternative: deploy a423 Conformance Pack with cloudformation-stack-drift-detection-check424 alarming to the SRE SNS topic.425```426427## Expert edge cases428429Expert edge cases (10 non-obvious drift behaviours) moved verbatim to [references/advanced-patterns.md](references/advanced-patterns.md).430Load on demand when the drift signal does not match the obvious pattern.431432## Expert heuristic — "Read the per-resource ResourceDriftStatus, not the stack-level StackDriftStatus"433434Expert heuristic — per-resource ResourceDriftStatus lookup table moved verbatim to [references/advanced-patterns.md](references/advanced-patterns.md).435Load on demand when classifying per-resource findings into resolutions.436437## Anti-Patterns — NEVER438439- **NEVER** treat `StackDriftStatus: DRIFTED` as the root cause. It440 is the symptom. The per-resource `ResourceDriftStatus` and441 `PropertyDifferences` are the diagnosis.442- **NEVER** recommend `update-stack` to reset drift on a resource443 whose drifted property is immutable without explicitly warning that444 the update triggers Replacement. Always probe with a ChangeSet445 first.446- **NEVER** recommend `import-resources` without verifying that the447 template properties match the actual physical resource exactly.448 Mismatch causes `IMPORT_FAILED`.449- **NEVER** declare `ROOT_CAUSE_FOUND` without naming the out-of-band450 actor (or explicitly stating that the CloudTrail event was not451 found and the actor is unknown).452- **NEVER** rely on a stale `StackDriftStatus` from the console.453 Always run `detect-stack-drift` fresh before diagnosing, then poll454 `describe-stack-drift-detection-status` to confirm completion.455- **NEVER** assume `IN_SYNC` on a stack with `NOT_CHECKED` resources456 means no drift exists. Drift detection does not cover all resource457 types; use AWS Config for full posture.458- **NEVER** treat `DeletionPolicy: Retain` resources as drifted when459 they persist after stack delete. They are intentionally retained;460 track them via AWS Config separately.461- **NEVER** run `update-stack` blind on a drifted stack. Always462 create and review a ChangeSet first, inspecting `Replacement` for463 every drifted resource.464- **NEVER** recommend a `Deny` IAM policy on the underlying service465 API without the `aws:CalledViaFirst: cloudformation.amazonaws.com`466 condition — an unconditional deny breaks CloudFormation itself.467- **NEVER** assume `cdk drift` output maps 1:1 to CloudFormation468 resource drift. Always cross-reference469 `describe-stack-resource-drifts` for resource-level detail.470- **NEVER** assume a nested stack's parent drift reflects the root471 cause. Drill into the child stack — the parent's472 `AWS::CloudFormation::Stack` resource only carries the child's473 status.474- **NEVER** conclude drift resolution without re-running475 `detect-stack-drift` and confirming `StackResourceDriftStatus:476 IN_SYNC` on every previously-drifted resource.477478## Recent AWS features (2024-2026)479480Recent AWS features (nested-stack drift, resource import, cdk drift, IaC Generator, Hooks) moved verbatim to [references/advanced-patterns.md](references/advanced-patterns.md).481Load on demand when confirming feature availability or vintage.482483## References484485See `references/drift-types-and-resolution.md` for the full486per-drift-type decision matrix with worked examples for each487resolution strategy, and `references/diagnostic-commands.md` for the488canonical command script for drift detection, forensic walk, and489remediation.490491## References (load on demand)492493- [references/drift-types-and-resolution.md](references/drift-types-and-resolution.md) — full per-drift-type decision matrix and resolution playbook.494- [references/diagnostic-commands.md](references/diagnostic-commands.md) — canonical command script; now also holds the Step 5 resource-import flow moved from SKILL.md.495- [references/advanced-patterns.md](references/advanced-patterns.md) — expert edge-case catalog, Step 8 IAM prevention deep dive, per-resource heuristic, and recent AWS features moved from SKILL.md.496497## Domain498499AWS CloudOps / DevTools — Infrastructure-as-Code Configuration500Compliance.501502## AWS documentation503504- **AWS CloudFormation drift detection** — https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-stack-drift.html505- **Resource import** — https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/resource-import.html506- **CloudFormation Hooks** — https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/hooks.html507- **`aws:CalledViaFirst` condition key** — https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-calledviafirst508- **AWS Config conformance packs** — https://docs.aws.amazon.com/config/latest/developerguide/conformance-packs.html509- **CDK drift** — https://docs.aws.amazon.com/cdk/v2/guide/drift.html510- **CLI Reference** — https://docs.aws.amazon.com/cli/latest/reference/cloudformation/