Compares deployed CloudFormation templates with locally synthesized CDK templates to detect drift, validate changes, and ensure consistency before deployment. Use when the user wants to compare CDK output with a deployed stack, check for infrastructure drift, run a pre-deployment validation, audit IAM or security changes, investigate a failing deployment, or perform a 'cdk diff'-style review. Triggered by phrases like 'compare templates', 'check for drift', 'cfn drift', 'stack comparison', 'infrastructure drift detection', 'safe to deploy', or 'what changed in my CDK stack'.
Does it follow best practices?
Evaluation — 100%
↑ 1.09xAgent success when using this tile
Validation for skill structure
This is an example of the markdown report generated by the compare-cfn-templates.sh script.
Generated: 2026-02-18 15:30:45 UTC Deployed Stack: lct-monitoring-st Region: eu-west-1 Profile: ppl-sw-st Local Branch: feat-CC-990-clean-subscription-fix PPLAWS Reference: thoroc
| Metric | Deployed | Local | Status |
|---|---|---|---|
| Total Resources | 55 | 55 | ✅ |
| Common Resources | 48 | 48 | ✅ |
| Added Resources | 0 | 7 | ⚠️ |
| Removed Resources | 7 | 0 | ⚠️ |
✅ Template structure matches - Both templates have identical top-level keys
The following 7 resource(s) exist in the local template but not in deployed:
AWS::EC2::SecurityGroupIngress)AWS::EC2::SecurityGroupIngress)AWS::Lambda::Permission)AWS::CloudWatch::Alarm)AWS::CloudWatch::Alarm)AWS::CloudWatch::Alarm)AWS::Lambda::Permission)The following 7 resource(s) exist in the deployed template but not in local:
AWS::EC2::SecurityGroupIngress)AWS::EC2::SecurityGroupIngress)AWS::Lambda::Permission)AWS::CloudWatch::Alarm)AWS::CloudWatch::Alarm)AWS::CloudWatch::Alarm)AWS::Lambda::Permission)| Environment | Resources with Suppressions |
|---|---|
| Deployed | 54 |
| Local | 54 |
✅ CDK Nag suppressions are consistent
Templates have differences that require careful review before deployment.
Required Actions:
Impact Assessment:
The following files are available in this directory for detailed analysis:
deployed.json - Complete CloudFormation template from deployed stacklocal.json - Complete CloudFormation template from local synthesisdeployed-resources.txt - List of deployed resource logical IDslocal-resources.txt - List of local resource logical IDsdeployed-keys.txt - Deployed template top-level keyslocal-keys.txt - Local template top-level keysjq '.Resources["<ResourceLogicalId>"]' deployed.json
jq '.Resources["<ResourceLogicalId>"]' local.jsonjq -r '.Resources | to_entries[] | select(.value.Type == "AWS::Lambda::Function") | .key' local.jsonjq '.Resources | to_entries[] | select(.value.Type == "AWS::IAM::Role")' deployed.json > deployed-iam.json
jq '.Resources | to_entries[] | select(.value.Type == "AWS::IAM::Role")' local.json > local-iam.json
diff deployed-iam.json local-iam.jsonReport Generated by: cfn-template-compare skill
Timestamp: 2026-02-18T15:30:45Z
Share the markdown report with stakeholders before deployments to review changes and assess risks.
Example workflow:
Attach the report to change management tickets for approval workflows.
Example:
JIRA Ticket: INFRA-1234
Subject: Deploy LCT Monitoring Stack Updates
Attachment: 2026-02-18-153045_deployed-main_local-feat-CC-990_ref-thoroc/comparison-report.md
Change Summary:
- 7 resources will be renamed due to PPLAWS_REFERENCE change
- No functional changes
- Security suppressions remain consistentPreserve reports as part of compliance and audit documentation showing infrastructure changes over time.
Example structure:
audit-artifacts/
2026-Q1/
2026-02-18-153045_deployed-main_local-feat-CC-990_ref-thoroc/
2026-02-15-091230_deployed-main_local-main_ref-st/
2026-Q2/
...Compare historical reports to identify when specific changes were introduced that may have caused issues.
Example: "When did the CloudWatch alarm threshold change from 80% to 90%?"
Generate reports for ST, AT, and PR environments to ensure consistency across deployment pipeline.
Example workflow:
# Compare ST environment
bash compare-cfn-templates.sh lct-monitoring-st eu-west-1 ppl-sw-st
# Compare AT environment
bash compare-cfn-templates.sh lct-monitoring-at eu-west-1 ppl-sw-at
# Compare PR environment
bash compare-cfn-templates.sh lct-monitoring-pr eu-west-1 ppl-sw-pr
# Review all reports to ensure consistency
ls -l cfn-compare-results/| Icon | Meaning |
|---|---|
| ✅ | No differences, safe |
| ⚠️ | Differences detected, review needed |
✅ SAFE TO DEPLOY:
⚠️ REVIEW REQUIRED:
Control report generation behavior with environment variables:
# Disable artifact preservation (cleanup after comparison)
PRESERVE_ARTIFACTS=false bash compare-cfn-templates.sh lct-monitoring-st eu-west-1 ppl-sw-st
# Keep artifacts (default behavior)
PRESERVE_ARTIFACTS=true bash compare-cfn-templates.sh lct-monitoring-st eu-west-1 ppl-sw-stManage disk space by removing old comparison reports:
# Keep only last 10 comparison runs
cd cfn-compare-results
ls -t | tail -n +11 | xargs rm -rf
# Remove reports older than 30 days
find cfn-compare-results -type d -mtime +30 -exec rm -rf {} +
# Remove all comparison artifacts
rm -rf cfn-compare-results/