Documentation ¶
Overview ¶
Package cami provides a simple service for keeping AMIs clean.
Example ¶
package main import ( "errors" "fmt" "strings" "github.com/lingrino/cami/cami" ) func main() { var err error aws, err := cami.NewAWS(&cami.Config{DryRun: false}) if err != nil { fmt.Printf("ERROR: %v\n", err) } err = aws.Auth() if err != nil { fmt.Printf("ERROR: %v\n", err) } deleted, err := aws.DeleteUnusedAMIs() if len(deleted) == 0 && err == nil { fmt.Println("nothing to delete") } var eda *cami.DeleteAMIError if err != nil { if errors.As(err, &eda) { fmt.Printf("Failed to delete:\n %s\n", strings.Join(eda.IDs, "\n ")) } else { fmt.Printf("UNKNOWN ERROR: %v\n", err) } } if len(deleted) > 0 { fmt.Printf("Successfully deleted:\n %s\n", strings.Join(deleted, "\n ")) } }
Output:
Index ¶
- Variables
- type AWS
- func (a *AWS) AMIs() ([]types.Image, error)
- func (a *AWS) Auth() error
- func (a *AWS) DeleteAMIs(amis []types.Image) ([]string, error)
- func (a *AWS) DeleteUnusedAMIs() ([]string, error)
- func (a *AWS) EC2s(amis []types.Image) ([]types.Instance, error)
- func (a *AWS) FilterAMIs(amis []types.Image, ec2s []types.Instance) ([]types.Image, error)
- type Config
- type DeleteAMIError
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrCreateSession is when we fail to create an AWS session. ErrCreateSession = errors.New("create session") // ErrDesribeImages is when we fail to describe EC2 images. ErrDesribeImages = errors.New("describe images") // ErrDesribeInstances is when we fail to describe EC2 instances. ErrDesribeInstances = errors.New("describe instances") // ErrDeregisterImage is when we fail to deregister an image (AMI). ErrDeregisterImage = errors.New("deregister image") // ErrDeleteSnapshot is when we fail to delete a snapshot. ErrDeleteSnapshot = errors.New("delete snapshot") // ErrFilterAMIs is when when we fail to filter AMIs and EC2 instances. ErrFilterAMIs = errors.New("filter AMIs") )
Functions ¶
This section is empty.
Types ¶
type AWS ¶
type AWS struct {
// contains filtered or unexported fields
}
AWS is the main struct that holds our client and info.
func (*AWS) DeleteAMIs ¶
DeleteAMIs deregisters all AMIs in the provided list and deletes the snapshots associated with the deregistered AMI. Returns a list of IDs that were successfully deleted. If DryDrun == true does not actually delete.
func (*AWS) DeleteUnusedAMIs ¶
DeleteUnusedAMIs finds and deletes all AMIs (and their associated snapshots) that are not being used by any current EC2 instances in the same account.
type Config ¶
type Config struct { // Set to true to run non-destructively DryRun bool }
Config holds the configuration for our AWS struct.
type DeleteAMIError ¶ added in v1.3.5
type DeleteAMIError struct { // IDs is the list of AMI and snapshot IDs we failed to delete IDs []string }
DeleteAMIError is when we fail to delete (deregister image + snapshot delete) an image (AMI).
func (*DeleteAMIError) Append ¶ added in v1.3.5
func (e *DeleteAMIError) Append(ids ...string)
Append adds a new ID to the list of IDs.
func (*DeleteAMIError) Error ¶ added in v1.3.5
func (e *DeleteAMIError) Error() string
Error returns the error string for DeleteAMIError.
func (*DeleteAMIError) ErrorOrNil ¶ added in v1.3.5
func (e *DeleteAMIError) ErrorOrNil() error
ErrorOrNil returns nil if IDs is empty and the error otherwise.