amiclean

package
v0.0.0-...-e620c05 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 4, 2023 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RFC8601 is the date/time format used by AWS.
	RFC8601 = "2006-01-02T15:04:05.000Z"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AMIClean

type AMIClean struct {
	NamePrefix     string
	Delete         bool
	Tag            *ec2.Tag
	Invert         bool
	Unused         bool
	ExpirationDate time.Time
	Logger         *zap.Logger
	EC2Client      *ec2.EC2
}

AMIClean defines parameters for cleaning up AMIs based on a tag and expiration date.

func (*AMIClean) CheckImage

func (a *AMIClean) CheckImage(image *ec2.Image) bool

CheckImage compares a given image to the purge criteria and returns true if the image matches the criteria.

func (*AMIClean) CheckUnused

func (a *AMIClean) CheckUnused(image *ec2.Image) (bool, error)

CheckUnused takes an image and then checks to see if it is in use as an instance. If the image is in use, it should return false; if it is not in use, it should return true. Note that we're only checking for AMIs we own with this account in this account; if we've shared them with other accounts, we have no idea if they are being used (and finding out is nontrivial, unfortunately). TODO: Also check to see if we are using it for any ASG launch configurations. This is more difficult because you cannot filter them by AMI ID like you can with instances; you have to fetch all of them and then parse through them doing the comparison, making it much more onerous. :/

func (*AMIClean) GetImages

func (a *AMIClean) GetImages() (*ec2.DescribeImagesOutput, error)

GetImages gets us all the private AMIs on our account so that they can be looked through later. We have to do this here because the AWS API does not allow you to search for AMIs by creation date or by *not* having a tag set to a certain value, which would speed this up considerably.

func (*AMIClean) PurgeImage

func (a *AMIClean) PurgeImage(image *ec2.Image) (string, error)

PurgeImage operates on a single image, registering the image and deleting any associated snapshots. We return the ID of the AMI we deleted (in case that is interesting) and any errors.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL