A lightweight CLI tool to automatically clean up AWS CloudFormation stacks matching a specified prefix. Perfect for cleaning up development or testing stacks to avoid unnecessary AWS costs.
- List CloudFormation stacks filtered by prefix
- Batch delete stacks matching a prefix
- Configurable AWS region support
- Interactive deletion confirmation
- Detailed logging of operations
- Timeout handling for long-running deletions
go install github.com/thisguymartin/cfn-cleanup-go@latest
Download the latest binary from the releases page.
# Clone the repository
git clone https://github.com/thisguymartin/cfn-cleanup-go.git
# Change into directory
cd cfn-cleanup-go
# Build
go build -o cfn-cleanup
# Optional: Move to a directory in your PATH
sudo mv cfn-cleanup /usr/local/bin/
# Basic usage with default prefix
cfn-cleanup
# Specify a custom prefix
cfn-cleanup -prefix="your-stack-prefix"
# Specify AWS region
cfn-cleanup -prefix="your-stack-prefix" -region="us-west-1"
# Delete Cloudformations based on region and prefix
cfn-cleanup -prefix="your-stack-prefix" -region="us-west-1" -delete=true
Flag | Description | Default |
---|---|---|
-prefix |
Stack name prefix to match | "thisguymartin-pit" |
-region |
AWS region | AWS_REGION env variable |
The tool uses the standard AWS SDK credential chain. You can provide credentials in several ways:
- Environment variables (
AWS_ACCESS_KEY_ID
,AWS_SECRET_ACCESS_KEY
) - AWS credentials file (
~/.aws/credentials
)