func (c *cfS3BucketCleanup) removeUnusedCFBuckets() []*s3.Error { var ( errors = []*s3.Error{} objects []*s3.Object ) resp, err := c.s3SVC.ListBuckets(&s3.ListBucketsInput{}) easylogger.LogFatal(err) for _, bucket := range resp.Buckets { if isCloudformationBucket(*bucket.Name, c.bucketFilter) && c.isBucketDeletable(bucket) { easylogger.Log("This bucket is to be deleted: ", *bucket.Name) objects = c.getBucketContents(bucket) if !isBucketEmpty(objects) { errs := c.emptyBucket(bucket, objects) if len(errs) > 0 { errors = append(errors, errs...) continue } } _, err := c.s3SVC.DeleteBucket( &s3.DeleteBucketInput{ Bucket: bucket.Name, }, ) easylogger.LogFatal(err) } } return errors }
func main() { svc := &cfS3BucketCleanup{ cfSVC: cloudformation.New(getSessionConfigs()), s3SVC: s3.New(getSessionConfigs()), bucketFilter: *bucketFilter, } svc.getAllCfStackNames() errs := svc.removeUnusedCFBuckets() if len(errs) > 0 { for _, err := range errs { easylogger.Log("Error: ", err.Message) } os.Exit(1) } }