Skip to content

Commit

Permalink
Try setting region in LoadDefaultConfig
Browse files Browse the repository at this point in the history
Signed-off-by: Tiger Kaovilai <[email protected]>
  • Loading branch information
kaovilai committed Jul 16, 2024
1 parent 96ba76b commit be32d26
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions pkg/storage/aws/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,20 @@ func BucketRegionIsDiscoverable(bucket string) bool {
// modified to aws-sdk-go-v2
func GetBucketRegion(bucket string) (string, error) {
var region string
cfg, err := config.LoadDefaultConfig(context.TODO())
// GetBucketRegion will attempt to get the region for a bucket using the client's configured region to determine
// which AWS partition to perform the query on.
// Client therefore needs to be configured with region.
// In local dev environments, you might have ~/.aws/config that could be loaded and set with default region.
// In cluster/CI environment, ~/.aws/config may not be configured, so set region explicitly.
cfg, err := config.LoadDefaultConfig(context.TODO(), config.WithRegion("us-east-1"))
if err != nil {
// handle error
return "", err
}
fmt.Printf("config: %+v", cfg)
region, err = manager.GetBucketRegion(context.Background(), s3.NewFromConfig(cfg), bucket)
if region != "" {
return region, nil
}
fmt.Printf("config: %+v", cfg)
return "", errors.New("unable to determine bucket's region: " + err.Error())
}

0 comments on commit be32d26

Please sign in to comment.