This project provides tools for cleaning up Packer builds and related resources. It helps automate the process of removing unused or obsolete artifacts generated by Packer, streamlining infrastructure management.
The Docker image for this project was manually created using the following command:
docker build --push --platform linux/amd64,linux/arm64 -t cuotos/packer-cleaner .
This builds and pushes a multi-platform image (amd64 and arm64) to Docker Hub under the tag cuotos/packer-cleaner.
The main script (code/index.py) automates the cleanup of AWS EC2 instances created by Packer. It:
- Connects to AWS EC2 using boto3.
- Searches for instances with:
- Key name matching
packer_* - Tag
Nameset toPacker Builder - State of
stoppedorrunning
- Key name matching
- Checks the launch time of each instance.
- If an instance is older than the configured maximum age (default: 24 hours, set via the
MAX_AGEenvironment variable), it is marked for action. - Depending on the
METHODenvironment variable:stop: Stops the old instancesterminate: Terminates the old instances- Any other value: Only logs the instances without taking action
This helps ensure that obsolete Packer builder instances do not linger in your AWS account.