Bird
Raised Fist0
AWScloud~10 mins

Stack drift detection in AWS - Step-by-Step Execution

Choose your learning style10 modes available
Process Flow - Stack drift detection
Start Drift Detection
↓
Compare Stack Template
↓
Compare Stack Resources
↓
Check for Differences?
No→No Drift Detected
Yes↓
Report Drift Details
↓
End Drift Detection
The process starts by comparing the current stack template and resources with the deployed stack to find any differences, then reports if drift is detected.
Execution Sample
AWS
aws cloudformation detect-stack-drift --stack-name MyStack
aws cloudformation describe-stack-drift-detection-status --stack-drift-detection-id driftId
aws cloudformation describe-stack-drift-detection-status --stack-drift-detection-id driftId
aws cloudformation describe-stack-resource-drifts --stack-name MyStack
This sequence detects drift on a stack, checks detection status, and lists resource drifts.
Process Table
StepActionEvaluationResult
1Start drift detection on stack 'MyStack'Send detect-stack-drift API callDrift detection started, driftId received
2Check drift detection statusPoll describe-stack-drift-detection-status with driftIdStatus: IN_PROGRESS
3Check drift detection status againPoll describe-stack-drift-detection-status with driftIdStatus: COMPLETED
4Retrieve resource drift detailsCall describe-stack-resource-drifts for 'MyStack'List of resources with drift status
5Analyze drift resultsCompare resource drift statusesReport drift found on some resources
6End drift detectionNo further actionDrift detection complete
💡 Drift detection completes when status is COMPLETED and resource drifts are reported.
Status Tracker
VariableStartAfter Step 1After Step 3After Step 4Final
driftIdnullabc123abc123abc123abc123
detectionStatusnullIN_PROGRESSCOMPLETEDCOMPLETEDCOMPLETED
resourceDriftsemptyemptyempty[Resource1: IN_SYNC, Resource2: MODIFIED][Resource1: IN_SYNC, Resource2: MODIFIED]
Key Moments - 3 Insights
Why does drift detection take time and show IN_PROGRESS status?
Because AWS CloudFormation compares all stack resources and templates, which can take time; see execution_table rows 2 and 3 showing status polling.
What does it mean if a resource shows MODIFIED in drift results?
It means the actual resource configuration differs from the stack template; see execution_table row 5 where drift is reported.
Can drift detection fix the drift automatically?
No, drift detection only reports differences; you must update or fix the stack manually.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the drift detection status at step 3?
AFAILED
BIN_PROGRESS
CCOMPLETED
DNOT_STARTED
💡 Hint
Check the 'Evaluation' column at step 3 in execution_table.
At which step are the resource drift details retrieved?
AStep 2
BStep 4
CStep 3
DStep 5
💡 Hint
Look for the action 'Retrieve resource drift details' in execution_table.
If no differences are found, what would the result be at step 5?
AReport no drift detected
BDetection status IN_PROGRESS
CReport drift found on some resources
DError retrieving drift details
💡 Hint
Refer to execution_table row 5 and the exit_note about drift reporting.
Concept Snapshot
Stack Drift Detection:
- Start detection with 'detect-stack-drift' command
- Poll status until COMPLETED
- Retrieve resource drift details
- Drift means actual differs from template
- Detection reports drift; manual fix needed
Full Transcript
Stack drift detection in AWS CloudFormation starts by sending a detect-stack-drift command for a stack. The system then compares the deployed stack's resources and template with the current template. This process takes time, so the status is polled until it shows COMPLETED. After completion, resource drift details are retrieved, showing which resources are in sync or modified. If differences exist, drift is reported. Drift detection only reports differences; it does not fix them automatically.

Practice

(1/5)
1.

What is the main purpose of stack drift detection in AWS CloudFormation?

easy
A. To find manual changes made outside of CloudFormation templates
B. To automatically fix errors in CloudFormation templates
C. To create new stacks from existing templates
D. To monitor network traffic between AWS resources

Solution

  1. Step 1: Understand stack drift detection concept

    Stack drift detection checks if resources in a stack have been changed manually or outside CloudFormation management.
  2. Step 2: Identify the main purpose

    The main goal is to find these manual or unexpected changes to keep infrastructure consistent.
  3. Final Answer:

    To find manual changes made outside of CloudFormation templates -> Option A
  4. Quick Check:

    Stack drift detection = find manual changes [OK]
Hint: Stack drift detection finds changes outside CloudFormation [OK]
Common Mistakes:
  • Thinking it fixes errors automatically
  • Confusing it with stack creation
  • Assuming it monitors network traffic
2.

Which AWS CLI command starts drift detection for a CloudFormation stack named MyAppStack?

easy
A. aws cloudformation begin-drift-check --name MyAppStack
B. aws cloudformation detect-stack-drift --stack-name MyAppStack
C. aws cloudformation start-drift-detection --stack MyAppStack
D. aws cloudformation check-drift --stack-name MyAppStack

Solution

  1. Step 1: Recall AWS CLI syntax for drift detection

    The correct command to start drift detection is detect-stack-drift with the --stack-name option.
  2. Step 2: Match the command with the stack name

    aws cloudformation detect-stack-drift --stack-name MyAppStack uses the exact syntax and correct parameter for the stack name.
  3. Final Answer:

    aws cloudformation detect-stack-drift --stack-name MyAppStack -> Option B
  4. Quick Check:

    Detect drift command = detect-stack-drift [OK]
Hint: Use 'detect-stack-drift' with '--stack-name' to start detection [OK]
Common Mistakes:
  • Using incorrect command verbs like start or begin
  • Wrong parameter names like --stack or --name
  • Mixing up command order or syntax
3.

After running aws cloudformation detect-stack-drift --stack-name MyStack, which command shows the drift detection status and results?

medium
A. aws cloudformation show-drift-results --stack-name MyStack
B. aws cloudformation get-stack-drift-status --stack-name MyStack
C. aws cloudformation list-stack-drift-detection --stack-name MyStack
D. aws cloudformation describe-stack-drift-detection-status --stack-drift-detection-id

Solution

  1. Step 1: Identify the command to check drift detection status

    The AWS CLI command to check drift detection status is describe-stack-drift-detection-status.
  2. Step 2: Confirm the correct parameter usage

    It requires the --stack-drift-detection-id parameter to specify the detection ID, not --stack-name.
  3. Final Answer:

    aws cloudformation describe-stack-drift-detection-status --stack-drift-detection-id <detection-id> -> Option D
  4. Quick Check:

    Check drift status = describe-stack-drift-detection-status [OK]
Hint: Use 'describe-stack-drift-detection-status' with detection ID to get drift results [OK]
Common Mistakes:
  • Using non-existent commands like get-stack-drift-status
  • Confusing list commands with status commands
  • Wrong parameter names
4.

You ran aws cloudformation detect-stack-drift --stack-name TestStack but got an error: Stack with id TestStack does not exist. What is the most likely cause?

medium
A. The stack name is misspelled or the stack does not exist
B. Drift detection is not supported for this stack type
C. You need to add --region parameter to the command
D. The AWS CLI version is outdated and cannot run drift detection

Solution

  1. Step 1: Analyze the error message

    The error says the stack with the given name does not exist, indicating a wrong name or missing stack.
  2. Step 2: Consider other causes

    While region or CLI version issues can cause errors, this specific message points to a missing or misspelled stack name.
  3. Final Answer:

    The stack name is misspelled or the stack does not exist -> Option A
  4. Quick Check:

    Error about stack id means wrong or missing stack [OK]
Hint: Check stack name spelling and existence first [OK]
Common Mistakes:
  • Assuming region parameter is always required
  • Blaming CLI version without checking stack
  • Ignoring the exact error message
5.

You want to ensure your CloudFormation stack stays consistent with its template. Which approach best uses stack drift detection to maintain this?

A) Run drift detection regularly and update stack if drift is detected.
B) Disable drift detection and manually check resources.
C) Use drift detection only after stack deletion.
D) Ignore drift detection and rely on CloudWatch alarms.

hard
A. Use drift detection only after stack deletion
B. Disable drift detection and manually check resources
C. Run drift detection regularly and update stack if drift is detected
D. Ignore drift detection and rely on CloudWatch alarms

Solution

  1. Step 1: Understand drift detection best practice

    Regularly running drift detection helps find manual changes early and keeps the stack consistent.
  2. Step 2: Evaluate options

    Run drift detection regularly and update stack if drift is detected uses drift detection proactively. Options B, C, and D either ignore drift detection or use it incorrectly.
  3. Final Answer:

    Run drift detection regularly and update stack if drift is detected -> Option C
  4. Quick Check:

    Regular drift detection = best practice [OK]
Hint: Run drift detection regularly to catch changes early [OK]
Common Mistakes:
  • Ignoring drift detection completely
  • Checking drift only after deletion
  • Relying solely on CloudWatch for drift
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard