Skip to content

Commit

Permalink
Complete migration to AWS Go client V2.
Browse files Browse the repository at this point in the history
  • Loading branch information
balamut-google committed Mar 4, 2025
1 parent 1230f5b commit 00f2313
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
9 changes: 6 additions & 3 deletions aws-janitor/resources/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"net/http"
"strings"

"github.com/aws/aws-sdk-go/aws/awserr"
awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http"

"github.com/pkg/errors"
"github.com/sirupsen/logrus"
Expand All @@ -47,8 +47,11 @@ func CleanAll(opts Options, region string) error {
set, err := typ.ListAll(opts)
if err != nil {
// ignore errors for resources we do not have permissions to list
if reqerr, ok := errors.Cause(err).(awserr.RequestFailure); ok {
if reqerr.StatusCode() == http.StatusForbidden {
if resperr, ok := errors.Cause(err).(*awshttp.ResponseError); ok {
var responseError interface {
HTTPStatusCode() int
}
if resperr.As(&responseError) && responseError.HTTPStatusCode() == http.StatusForbidden {
logger.Debugf("Skipping resources of type %T, account does not have permission to list", typ)
continue
}
Expand Down
8 changes: 4 additions & 4 deletions aws-janitor/resources/s3_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ func (S3Bucket) MarkAndSweep(opts Options, set *Set) error {
opt.Region = opts.Region
})

// ListBucket lists all buckets owned by the authenticated sender of the request
// https://pkg.go.dev/github.com/aws/aws-sdk-go/service/s3#S3.ListBuckets
// ListBuckets lists all buckets owned by the authenticated sender of the request
// https://pkg.go.dev/github.com/aws/aws-sdk-go-v2/service/s3#Client.ListBuckets
// regardless the region configured in client.
resp, err := svc.ListBuckets(context.TODO(), &s3v2.ListBucketsInput{})
if err != nil {
Expand Down Expand Up @@ -130,8 +130,8 @@ func (S3Bucket) ListAll(opts Options) (*Set, error) {
opt.Region = opts.Region
})

// ListBucket lists all buckets owned by the authenticated sender of the request
// https://pkg.go.dev/github.com/aws/aws-sdk-go/service/s3#S3.ListBuckets
// ListBuckets lists all buckets owned by the authenticated sender of the request
// https://pkg.go.dev/github.com/aws/aws-sdk-go-v2/service/s3#Client.ListBuckets
// regardless the region configured in client.
resp, err := svc.ListBuckets(context.TODO(), &s3v2.ListBucketsInput{})
if err != nil {
Expand Down

0 comments on commit 00f2313

Please sign in to comment.