A powerful CLI tool for bulk-deleting AWS CloudFormation stacks using glob patterns. Perfect for cleaning up development environments, CI/CD temporary stacks, and feature branch deployments.
CF Purge is a powerful tool that PERMANENTLY DELETES AWS CloudFormation stacks and their resources.
- π¨ Always test in non-production environments first
- π Understand the implications of deleting your infrastructure
- πΎ Have proper backups of critical data
- β Use specific glob patterns to avoid accidental deletions
- π― Review the list of matched stacks before confirming deletion
This tool will prompt you for confirmation before deleting any stacks, but deletion is irreversible.
This repository is structured as a monorepo:
core/β Go CLI app for bulk-deleting CloudFormation stackswebsite/β Static website/landing pagedocs/β Documentation assets
Before using CF Purge, ensure you have:
- β AWS CLI configured with appropriate credentials
- β IAM permissions for CloudFormation operations (see AWS Configuration)
- β Go 1.22+ (only for building from source)
- β Basic understanding of CloudFormation stacks
- β Non-production environment for initial testing
brew tap dzhuneyt/tap
brew install cf-purge
cf-purge --version # Verify installationDownload the latest binary for your platform from GitHub Releases.
Supported platforms:
- Linux (amd64, arm64, 386)
- macOS (amd64, arm64)
- Windows (amd64, 386)
git clone https://github.com/Dzhuneyt/cf-purge.git
cd cf-purge/core
go build -o cf-purge main.gocf-purge --helpCreate an IAM policy with the following permissions:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"cloudformation:ListStacks",
"cloudformation:DeleteStack",
"cloudformation:DescribeStacks"
],
"Resource": "*"
}
]
}Ensure AWS credentials are configured via one of these methods:
- AWS CLI:
aws configure - Environment variables:
AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY - IAM roles (for EC2/Lambda execution)
- AWS profiles:
export AWS_PROFILE=your-profile
Verify your configuration:
aws sts get-caller-identitycf-purge --glob "PATTERN"# Delete all development environment stacks
cf-purge --glob "*-dev"
# Delete all stacks ending with "-api"
cf-purge --glob "*-api"
# Delete all stacks starting with "my-stack-"
cf-purge --glob "my-stack-*"
# Delete stacks matching a specific pattern
cf-purge --glob "*-feature-branch-*"cf-purge --glob "ci-build-*"
cf-purge --glob "*-pr-*"cf-purge --glob "*-feature-user-auth-*"
cf-purge --glob "myapp-branch-*"cf-purge --glob "*-dev"
cf-purge --glob "*-staging"
cf-purge --glob "test-*-tmp"cf-purge --glob "*-sandbox-*"
cf-purge --glob "*-playground-*"CF Purge will show you exactly which stacks match your pattern and ask for confirmation:
Glob pattern matched the following stacks:
----------------------------------------
my-app-dev-api
my-app-dev-database
my-app-dev-frontend
----------------------------------------
This operation will delete 3 stacks
THIS OPERATION IS DESTRUCTIVE AND IRREVERSIBLE
Please, confirm that you want to delete these stacks irreversibly.
[y/N]:
Type y and press Enter to proceed, or any other key to cancel.
- Cause: Insufficient IAM permissions
- Solution: Ensure your AWS credentials have the required CloudFormation permissions (see AWS Configuration)
- Cause: Stack resources have dependencies, deletion protection, or retain policies
- Solution:
- Check stack events in the AWS Console for specific resource errors
- Manually resolve resource dependencies
- Disable deletion protection on protected resources
- Cause: Glob pattern doesn't match any existing stack names
- Solution:
- List all stacks:
aws cloudformation list-stacks - Test your pattern with a broader glob first
- Check for typos in the pattern
- List all stacks:
- π Check Issues for similar problems
- π Review AWS CloudFormation documentation for stack deletion limitations
- π¬ Use
cf-purge --helpfor command options - π Report bugs or request features via GitHub Issues
- β‘ Processes stacks sequentially to avoid AWS API throttling
- π Large numbers of stacks may take several minutes to delete
- π No parallel deletion to ensure safe operation and proper confirmation (parallel deletion with configurable concurrency is planned for future releases)
- β Stack deletion failures require manual intervention (see roadmap)
- β No progress indicator for long-running operations
- β No dry-run mode (planned feature)
- π― Use specific patterns to avoid accidental deletions
- π§ͺ Test patterns in development environments first
- π¦ Delete in smaller batches for large numbers of stacks
- π Keep a record of important stacks before bulk operations
- β Delete by prefix or suffix, not just by glob pattern
- β CI to auto-publish to HomeBrew for easier installation and usage
- Dry-run mode - Preview which stacks would be deleted without actually deleting them
- Handle delete failures due to stack dependencies with automatic retries
- Progress indicators for long-running operations
- Parallel deletion with configurable concurrency
- Stack filtering by tags, creation date, or status
- Regex pattern support in addition to glob patterns
We welcome contributions! Here's how you can help:
git clone https://github.com/Dzhuneyt/cf-purge.git
cd cf-purge/core
go mod download
go run main.go --help- π Report bugs or request features via Issues
- π Improve documentation
- π§ͺ Add test cases
- β‘ Implement features from the roadmap
- π¨ Enhance the website
- Fork the repository
- Create a feature branch:
git checkout -b feature/your-feature-name - Make your changes in the
core/directory - Test thoroughly with non-production stacks
- Commit your changes:
git commit -m "Add your feature" - Push to your fork:
git push origin feature/your-feature-name - Submit a pull request with a clear description
This project is licensed under the MIT License - see the LICENSE file for details.
- π§ Issues: GitHub Issues
- π¬ Discussions: GitHub Discussions
- π Documentation: This README and GitHub Wiki
Remember: With great power comes great responsibility. Use CF Purge wisely! π