Skip to main content

AWS Hashicorp Packer Reaper

Hashicorp Packer is a great tool for building Amazon Machine Images. However, sometimes the virtual machine running packer is not stopped. This utility stops or terminated all virtual machines with the name tag 'Packer Builder'

You can use it as a command line utility or install it as an AWS Lambda function and stop the spend , NoOps style!

Since version 1.0.9, the default name tag was removed. To make it work with the reaper add a run_tags block to the builder:

source "amazon-ebs" "ubuntu" {
   name = "my_ubuntu"
   run_tags = {
     Name = "Packer Builder"
   }

install the packer reaper

to install the packer reaper, type:

pip install aws-hashicorp-packer-reaper

show running packer instances

To show running packer instances:

$ aws-hashicorp-packer-reaper list

i-06ac951992dbc11a1 (Packer Builder) launched 13 minutes ago - terminated
i-035ebe427a538c829 (Packer Builder) launched 4 minutes ago - running
INFO: 2 packer builder instances found

usage with multiple profiles

If you have multiple AWS Profiles (e.g. when working with AWS Organisations and SSO) you can specify the profile to use on the command line before executing the aws-hashicorp-packer-reaper.

$ AWS_PROFILE=not-my-default-profile aws-hashicorp-packer-reaper list

i-0d72937e04c1123a9 (Packer Builder) launched 31 minutes ago - running
i-0712d9bd593adb2fb (Packer Builder) launched 11 minutes ago - running
INFO: 2 packer builder instances found

stop running packer instances

To stop running packer instances older than 2 hours:

$ aws-hashicorp-packer-reaper stop --older-than 2h

INFO: stopping i-035ebe427a538c829 (Packer Builder) created 2 hours ago
INFO: total of 1 running instances stopped

terminate running packer instances

To terminate stopped and running packer instances older than 24 hours:

aws-hashicorp-packer-reaper --verbose terminate --older-than 24h

INFO: terminating i-035ebe427a538c829 (Packer Builder) created 25 hours ago
INFO: total of 1 instances terminated

deploy the packer reaper

To deploy the packer reaper as an AWS Lambda, type:

git clone https://github.com/binxio/aws-hashicorp-packer-reaper.git
cd aws-hashicorp-packer-reaper
aws cloudformation deploy \
	--capabilities CAPABILITY_IAM \
	--stack-name aws-hashicorp-packer-reaper \
	--template-file ./cloudformation/aws-hashicorp-packer-reaper.yaml

This will install the packer reaper in your AWS account and run every hour, stopping packer instances launched more than 2 hours ago and terminate instances older than 24 hours. You can change the schedule and the action to meet your requirements.

read the blog too! https://binx.io/blog/2020/03/27/how-to-terminate-packer-instances-on-aws/

Release files for aws-hashicorp-packer-reaper 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aws-hashicorp-packer-reaper 0.3.0
File Size Uploaded
aws-hashicorp-packer-reaper-0.3.0.tar.gz 11.1 kB Details

Release files / aws-hashicorp-packer-reaper-0.3.0.tar.gz

Download URL aws-hashicorp-packer-reaper-0.3.0.tar.gz
Size 11.1 kB
Tags Source
SHA-256 checksum
How to use checksums
4a30945cdcf5c5333933c695b2c48fd8f9e5084d66793d32ed2dd9d058705036
BLAKE2b-256 checksum
How to use checksums
5504205151b563fb70a6650801beb8aebac20d39f9458662239c9ddbaee41b49
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.7.6

Release history Release notifications | RSS feed

This release

0.3.0 This release

1 release file

0.2.0

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.1

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page