Skip to content

Conversation

@hoegertn
Copy link
Contributor

@hoegertn hoegertn commented Jan 29, 2026

Description

This PR adds a new resource counting feature that monitors CloudFormation resource usage across stacks during the CDK synthesis step. The feature helps teams stay aware of CloudFormation's 500 resource per stack limit and provides warnings when approaching this threshold.

Changes

New Features

  • Resource Counter Tool (src/awscdk/count-resources.ts): A new CLI tool that analyzes CloudFormation templates in the cloud assembly and counts resources per stack
  • ResourceCountStep (src/awscdk/resource-count-step.ts): A new pipeline step that integrates resource counting into CI/CD workflows
  • Configuration Options: Added two new options to CDKPipelineOptions:
    • enableResourceCounting (default: true): Toggle resource counting on/off
    • resourceCountWarningThreshold (default: 450): Configurable warning threshold

Pipeline Integration

  • GitHub: Automatically creates a PR workflow that counts resources and comments on pull requests with detailed resource usage tables
  • GitLab: Automatically creates an MR job that posts resource count summaries to merge requests
  • Bash: Supports resource counting in bash-based pipelines

Output Formats

  • Console output with per-stack breakdown and warnings
  • JSON results file (resource-count-results.json) for programmatic access
  • GitHub step summary integration for workflow visibility
  • PR/MR comments with formatted tables and recommendations

Benefits

  • Early detection of stacks approaching CloudFormation limits
  • Actionable recommendations for stack optimization
  • Visibility into resource usage across the entire infrastructure
  • Helps prevent deployment failures due to resource limit violations

Configuration

Users can control the feature via pipeline options:

new GithubCDKPipeline(this, {
  enableResourceCounting: true,
  resourceCountWarningThreshold: 450,
  // ... other options
});

The feature is enabled by default but can be disabled by setting enableResourceCounting: false.

Implements issue #158 to enhance CDK synth with resource limit warnings:

- Add count-resources script to analyze CloudFormation templates
- Count resources per stack and warn when approaching 500 resource limit
- Default warning threshold at 450 resources (configurable)
- Add resource counts to GitHub workflow summary
- Add PR comments with resource count details on pull requests
- New CDKPipelineOptions: resourceCountWarningThreshold and enableResourceCounting

The feature is enabled by default and helps prevent hitting CloudFormation's
hard limit of 500 resources per stack by providing early warnings.
… support

- Move provideResourceCountStep() to base CDKPipeline class
- Update GitHub to use base implementation
- Add resource counting to GitLab synth job (writes to console)
- Add GitLab MR comment workflow for resource counts
- GitLab MR comments use GitLab API to post/update comments
- Resource counting now works consistently across GitHub and GitLab
@github-actions github-actions bot requested a review from Lock128 January 29, 2026 10:53
@hoegertn hoegertn changed the title Add CloudFormation resource counting feature feat: Add CloudFormation resource counting feature Jan 29, 2026
hoegertn and others added 2 commits January 29, 2026 11:53
Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants