From 19515a32273970a8664443093e5676a1b6a2e5d7 Mon Sep 17 00:00:00 2001 From: Tiger Kaovilai Date: Wed, 17 Jul 2024 09:53:24 -0400 Subject: [PATCH 1/4] provide a region hint of "us-west-2" in GetBucketRegion example --- feature/s3/manager/bucket_region.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/feature/s3/manager/bucket_region.go b/feature/s3/manager/bucket_region.go index a6a9781e5ec..fafc99d6ca1 100644 --- a/feature/s3/manager/bucket_region.go +++ b/feature/s3/manager/bucket_region.go @@ -25,7 +25,7 @@ const bucketRegionHeader = "X-Amz-Bucket-Region" // 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"), config.WithCredentialsProvider(aws.AnonymousCredentials{})) // if err != nil { // log.Println("error:", err) // return From 44aa01f227a35fd4d9d38c9478bf6a7f15b6e28a Mon Sep 17 00:00:00 2001 From: Luc Talatinian <102624213+lucix-aws@users.noreply.github.com> Date: Wed, 17 Jul 2024 13:01:20 -0400 Subject: [PATCH 2/4] Update feature/s3/manager/bucket_region.go Co-authored-by: Tiger Kaovilai --- feature/s3/manager/bucket_region.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/feature/s3/manager/bucket_region.go b/feature/s3/manager/bucket_region.go index fafc99d6ca1..22615ac0eda 100644 --- a/feature/s3/manager/bucket_region.go +++ b/feature/s3/manager/bucket_region.go @@ -25,7 +25,7 @@ const bucketRegionHeader = "X-Amz-Bucket-Region" // 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(), config.WithRegion("us-west-2"), config.WithCredentialsProvider(aws.AnonymousCredentials{})) +// cfg, err := config.LoadDefaultConfig(context.TODO(), config.WithRegion("us-west-2")) // if err != nil { // log.Println("error:", err) // return From f7a89262286d7ca7f2307a2df4214d0993d19f5d Mon Sep 17 00:00:00 2001 From: Tiger Kaovilai Date: Wed, 17 Jul 2024 13:11:56 -0400 Subject: [PATCH 3/4] Added note on anonymous credentials usage for GetBucketRegion Signed-off-by: Tiger Kaovilai --- feature/s3/manager/bucket_region.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/feature/s3/manager/bucket_region.go b/feature/s3/manager/bucket_region.go index 22615ac0eda..7fc13302c1e 100644 --- a/feature/s3/manager/bucket_region.go +++ b/feature/s3/manager/bucket_region.go @@ -17,8 +17,6 @@ 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. // @@ -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 From a2f07a901f3c7805a030457a37dc6ccc3a160051 Mon Sep 17 00:00:00 2001 From: Luc Talatinian Date: Wed, 17 Jul 2024 14:33:42 -0400 Subject: [PATCH 4/4] add changelog --- .changelog/45d613f9451e478c866ae676b72ab246.json | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 .changelog/45d613f9451e478c866ae676b72ab246.json diff --git a/.changelog/45d613f9451e478c866ae676b72ab246.json b/.changelog/45d613f9451e478c866ae676b72ab246.json new file mode 100644 index 00000000000..5a8aa5d287d --- /dev/null +++ b/.changelog/45d613f9451e478c866ae676b72ab246.json @@ -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" + ] +} \ No newline at end of file