func trimSnapshots(instId string, c *ec2.EC2) { filter := ec2.NewFilter() val := fmt.Sprintf("%s/%s", instId, *period) filter.Add("status", "completed") filter.Add("tag:inst_snap", val) resp, err := c.Snapshots(nil, filter) if err != nil { log.Printf("Error getting existing snapshots: ", err) } if len(resp.Snapshots) > *copies { excess := len(resp.Snapshots) - *copies extras := resp.Snapshots[:excess] log.Printf("Need %d have %d completed snapshots\n", *copies, len(resp.Snapshots)) for _, extra := range extras { log.Printf("Trimming %s for %sn", extra.Id, instId) _, err := c.DeleteSnapshots([]string{extra.Id}) if err != nil { log.Println("Failed trimming snapshot:", extra.Id, " Error: ", err) } } } }