Interview Prep/AWS/CloudFormation, CloudWatch, KMS, Secrets and Cost

Drift detection shows `MODIFIED` on a security group and an RDS instance that someone changed in the console. How do you reconcile?

AdvancedTroubleshootingCloudFormation, CloudWatch, KMS, Secrets and Cost
Answer

Likely causes → Changes made outside CloudFormation (console hotfix during an incident). The next stack update may silently undo them, or fail.

Diagnose →

ID=$(aws cloudformation detect-stack-drift --stack-name app --query StackDriftDetectionId --output text)
aws cloudformation describe-stack-drift-detection-status --stack-drift-detection-id $ID
aws cloudformation describe-stack-resource-drifts --stack-name app --stack-resource-drift-status-filters MODIFIED DELETED \
  --query 'StackResourceDrifts[].[LogicalResourceId,PropertyDifferences]'

Fix →

  1. Decide which version is correct
  2. If the console change should stay, put it into the template and deploy a change set (it should show no replacement)
  3. If not, deploy the template to overwrite it
  4. For resources deleted out of band, remove them from the template, or re-create and import them (create-change-set --change-set-type IMPORT)

Prevent → Run scheduled drift detection (AWS Config rule cloudformation-stack-drift-detection-check), make production console access read-only, and have a break-glass process that requires a follow-up PR.

aws All AWS questions Roadmap: Cloud cost & architecture

More on CloudFormation, CloudWatch, KMS, Secrets and Cost