Skip to content

Commit

Permalink
provide a region hint of "us-west-2" in GetBucketRegion example (#2716)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaovilai authored Jul 24, 2024
1 parent a46ec1d commit 17cc515
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
8 changes: 8 additions & 0 deletions .changelog/45d613f9451e478c866ae676b72ab246.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"id": "45d613f9-451e-478c-866a-e676b72ab246",
"type": "documentation",
"description": "Clarify region hint and credential usage in HeadBucketRegion.",
"modules": [
"feature/s3/manager"
]
}
13 changes: 10 additions & 3 deletions feature/s3/manager/bucket_region.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@ const bucketRegionHeader = "X-Amz-Bucket-Region"
// 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.
//
// The request will not be signed, and will not use your AWS credentials.
//
// A BucketNotFound error will be returned if the bucket does not exist in the
// AWS partition the client region belongs to.
//
// For example to get the region of a bucket which exists in "eu-central-1"
// you could provide a region hint of "us-west-2".
//
// cfg, err := config.LoadDefaultConfig(context.TODO())
// cfg, err := config.LoadDefaultConfig(context.TODO(), config.WithRegion("us-west-2"))
// if err != nil {
// log.Println("error:", err)
// return
Expand Down Expand Up @@ -60,6 +58,15 @@ const bucketRegionHeader = "X-Amz-Bucket-Region"
// if err != nil {
// panic(err)
// }
//
// If buckets are public, you may use anonymous credential like so.
// manager.GetBucketRegion(ctx, s3.NewFromConfig(cfg), bucket, func(o *s3.Options) {
// o.Credentials = nil
// // Or
// o.Credentials = aws.AnonymousCredentials{}
// })
// The request with anonymous credentials will not be signed.
// Otherwise credentials would be required for private buckets.
func GetBucketRegion(ctx context.Context, client HeadBucketAPIClient, bucket string, optFns ...func(*s3.Options)) (string, error) {
var captureBucketRegion deserializeBucketRegion

Expand Down

0 comments on commit 17cc515

Please sign in to comment.