https://github.com/bifravst/cloudformation-cleaner
Cleans old CloudFormation stacks and log groups, e.g. from CI runs
https://github.com/bifravst/cloudformation-cleaner
aws cloudformation iot nrf-asset-tracker utility
Last synced: 3 months ago
JSON representation
Cleans old CloudFormation stacks and log groups, e.g. from CI runs
- Host: GitHub
- URL: https://github.com/bifravst/cloudformation-cleaner
- Owner: bifravst
- License: bsd-3-clause
- Created: 2021-01-26T15:46:21.000Z (over 5 years ago)
- Default Branch: saga
- Last Pushed: 2025-06-12T16:47:17.000Z (about 1 year ago)
- Last Synced: 2025-06-12T17:43:07.318Z (about 1 year ago)
- Topics: aws, cloudformation, iot, nrf-asset-tracker, utility
- Language: TypeScript
- Homepage: https://github.com/bifravst/cloudformation-cleaner#readme
- Size: 13.7 MB
- Stars: 1
- Watchers: 5
- Forks: 2
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# AWS CloudFormation Cleaner
[](https://github.com/bifravst/cloudformation-cleaner/actions)
[](https://github.com/semantic-release/semantic-release)
[](https://renovatebot.com)
[](https://github.com/conventional-changelog/commitlint/tree/master/@commitlint/config-conventional)
[](https://github.com/prettier/prettier/)
[](https://github.com/typescript-eslint/typescript-eslint)
This is a [CDK](https://github.com/aws/aws-cdk) project written in TypeScript
that sets up a CloudFormation stack which cleans up left-over stacks and log
groups from CI runs.
Although your CI tests _should_ clean up after themselves, there still might be
stacks and log groups that get not cleaned up perfectly. This stack runs a
lambda every hour, which deletes stacks and log groups that have a certain
prefix and are older than 24 hours.
## Install
git clone https://github.com/bifravst/cloudformation-cleaner
npm ci
## Setup in your CI account
> Note: you should only set this up in an account where every CloudFormation
> stack can be deleted, because this lambda has the permissions to delete
> everything.
npx cdk deploy --context prefix=my-prefix-
You should specify the prefix your stacks use in the context variable `prefix`.
### Configuration
You can configure the regular expression used to check against a resources names
according to the following table
| Lambda | SSM Parameter Name |
| ------------------- | ---------------------------------- |
| `stack-cleaner` | `/${stackName}/stackNameRegEx` |
| `log-group-cleaner` | `/${stackName}/logGroupNameRegEx` |
| `role-cleaner` | `/${stackName}/roleNameRegEx` |
| `buckets-cleaner` | `/${stackName}/bucketNameRegEx` |
| `parameter-cleaner` | `/${stackName}/parameterNameRegEx` |
You can configure this from the command line:
```bash
aws ssm put-parameter --name /cloudformation-cleaner/stackNameRegEx --value '^(some-pattern|another-pattern)-' --type String --overwrite
aws ssm put-parameter --name /cloudformation-cleaner/parameterNameRegEx --value '^\/(some-pattern|another-pattern)-' --type String --overwrite
```
## Running from the command line
```bash
npm run clean
```