Skip to main content

Summarize AWS CDK diff JSON as compact Markdown.

Project description

cdk-diff-summary

cdk-diff-summary reads AWS CDK diff JSON and renders a compact Markdown summary.

This repository is the source of truth for both:

  • the GitHub Marketplace composite action jalcock501/cdk-diff-summary
  • the PyPI package cdk-diff-summary

It is designed for pull requests and CI jobs where raw CDK or CloudFormation diffs are too noisy. The summary groups adds, modifies, removes, replacements, security group rule changes, and other changes while reducing common churn from IAM policy documents and CDK asset hashes.

The tool deliberately shows changed field paths only, not before/after values, to avoid exposing sensitive infrastructure values in summaries.

GitHub Action Usage

- name: Generate CDK diff JSON
  run: npx cdk diff --json > cdk-diff.json

- name: Summarize CDK diff
  uses: jalcock501/cdk-diff-summary@v1
  with:
    diff-json-path: cdk-diff.json

The composite action runs the local checked-out code from the action tag. It does not install cdk-diff-summary from PyPI at runtime.

Action Inputs

Input Required Default Description
diff-json-path yes Path to JSON produced by cdk diff --json.
summary-title no CDK diff summary Markdown heading for the summary.
max-changed-fields no 8 Maximum changed field paths shown per resource.
collapse-iam-policies no true Collapse large IAM policy document diffs to a single path such as PolicyDocument.
collapse-assets no true Suppress or collapse common CDK asset/hash churn such as asset hashes, S3 object keys, Lambda code hashes, Docker image asset hashes, and CDK metadata asset paths.
fail-on-remove no false Write the summary, then fail the step if visible removes exist.
fail-on-replace no false Write the summary, then fail the step if visible replacements exist.
summary-output-path no Optional file path to also append the generated Markdown summary.

PyPI / CLI Usage

Install with pipx:

pipx install cdk-diff-summary

Generate CDK diff JSON:

npx cdk diff --json > cdk-diff.json

Render Markdown to stdout:

cdk-diff-summary cdk-diff.json

Append Markdown to a file:

cdk-diff-summary cdk-diff.json --output cdk-diff-summary.md

Use a custom title and field limit:

cdk-diff-summary cdk-diff.json \
  --title "Production CDK diff" \
  --max-changed-fields 5

Fail when visible removals or replacements exist:

cdk-diff-summary cdk-diff.json --fail-on-remove --fail-on-replace

CLI Options

Option Description
diff-json-path Path to JSON produced by cdk diff --json. May also be set with DIFF_JSON_PATH.
--title Markdown heading for the summary. Defaults to CDK diff summary.
--max-changed-fields Maximum changed field paths shown per resource. Defaults to 8.
--collapse-iam-policies / --no-collapse-iam-policies Collapse large IAM policy document diffs to compact paths. Enabled by default.
--collapse-assets / --no-collapse-assets Collapse common CDK asset/hash churn. Enabled by default.
--fail-on-remove / --no-fail-on-remove Write the summary, then exit non-zero if visible resource removes exist. Disabled by default.
--fail-on-replace / --no-fail-on-replace Write the summary, then exit non-zero if visible resource replacements exist. Disabled by default.
--output Optional path to append the generated Markdown summary.
--github-step-summary Optional path to append GitHub Step Summary Markdown. Defaults to $GITHUB_STEP_SUMMARY.

Environment variables compatible with the GitHub Action wrapper are also supported:

  • DIFF_JSON_PATH
  • SUMMARY_TITLE
  • MAX_CHANGED_FIELDS
  • COLLAPSE_IAM_POLICIES
  • COLLAPSE_ASSETS
  • FAIL_ON_REMOVE
  • FAIL_ON_REPLACE
  • SUMMARY_OUTPUT_PATH
  • GITHUB_STEP_SUMMARY

CLI arguments take precedence over environment variables.

Example Output

Screenshot of a larger CDK diff summary in GitHub Step Summary

## CDK diff summary

| Metric | Count |
| --- | ---: |
| Stack changes | 1 |
| Resource changes | 3 |
| Adds | 1 |
| Modifies | 1 |
| Removes | 0 |
| Replacements | 1 |
| Security group changes | 1 |
| Changes shown below | 4 |

### Replacements

| Stack | Logical ID | Action | Resource type | Changed fields |
| --- | --- | --- | --- | --- |
| PaymentsStack | Worker | replace | AWS::Lambda::Function | `Architectures[]`, `Layers[]` |

### Security group changes

| Stack | Security group | Direction | Protocol | Port | Action |
| --- | --- | --- | --- | --- | --- |
| PaymentsStack | AppSecurityGroup | ingress | tcp | 443 | add |

Local Development

python -m pip install -e ".[dev]"
python -m pytest
ruff check .
python -m build
twine check dist/*

Run the action wrapper directly:

DIFF_JSON_PATH=example_cdk_diff_json/cdk-diff-json-tiny.json \
GITHUB_STEP_SUMMARY=/tmp/cdk-summary.md \
python scripts/cdk_diff_summary.py

Run the installed CLI:

cdk-diff-summary example_cdk_diff_json/cdk-diff-json-tiny.json

CDK diff JSON shape can vary by CDK version. If parsing fails, please open an issue with a sanitized example of the JSON shape that failed.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cdk_diff_summary-1.1.2.tar.gz (14.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cdk_diff_summary-1.1.2-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

Details for the file cdk_diff_summary-1.1.2.tar.gz.

File metadata

  • Download URL: cdk_diff_summary-1.1.2.tar.gz
  • Upload date:
  • Size: 14.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for cdk_diff_summary-1.1.2.tar.gz
Algorithm Hash digest
SHA256 90040e7a48f5dfd6cdd8da9aad29749748d43dc212019aaf6a3eea307084cea7
MD5 8b0b6b2a171e83b2e1bf1516a1b10b2c
BLAKE2b-256 fe16ddf38e50acc2b1419cd05f27955a3d680227126c5b22934cdd7a834acdc6

See more details on using hashes here.

Provenance

The following attestation bundles were made for cdk_diff_summary-1.1.2.tar.gz:

Publisher: publish.yml on jalcock501/cdk-diff-summary

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cdk_diff_summary-1.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for cdk_diff_summary-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e492cb4c032b41fcb607a66837863e5403d102ef7e16c33e5586e4e66f4a8fa2
MD5 17241ad23088d4217083c02d7e037b72
BLAKE2b-256 bdc828a74fcac244839fdcac2c67bd4822ff879ed43546b5d258db4ac397a31a

See more details on using hashes here.

Provenance

The following attestation bundles were made for cdk_diff_summary-1.1.2-py3-none-any.whl:

Publisher: publish.yml on jalcock501/cdk-diff-summary

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page