Skip to content

Commit 829559e

Browse files
committed
s3: use HeadBucket for region discovery
Signed-off-by: Aaron Wilson <aawilson@nvidia.com>
1 parent 2b0c624 commit 829559e

1 file changed

Lines changed: 18 additions & 7 deletions

File tree

ais/backend/aws.go

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,18 @@ func NewAWS(t core.TargetPut, tstats stats.Tracker, startingUp bool) (core.Backe
101101

102102
const gotBucketLocation = "got_bucket_location"
103103

104+
// HeadBucket queries the backend S3 bucket and returns props
105+
//
106+
// `sessConf.region` is normally expected to come from bucket props or from
107+
// AWS SDK config resolution (`sessConf.options()` back-fills it from
108+
// `options.Region`).
109+
//
110+
// If region is still unknown after creating the client, avoid caching under
111+
// an incomplete (profile, region, endpoint) tuple.
112+
//
113+
// `gotBucketLocation` is a special-case tag used by HeadBucket()'s fallback
114+
// location probe. It does not pass the resolved region back here; it only
115+
// bypasses the early return below and permits caching on that path.
104116
func (*s3bp) HeadBucket(_ context.Context, bck *meta.Bck) (cos.StrKVs, int, error) {
105117
var (
106118
cloudBck = bck.RemoteBck()
@@ -143,18 +155,17 @@ func (*s3bp) HeadBucket(_ context.Context, bck *meta.Bck) (cos.StrKVs, int, erro
143155
return bckProps, 0, nil
144156
}
145157

146-
func _location(svc *s3.Client, bckName string) (region string, err error) {
147-
resp, err := svc.GetBucketLocation(context.Background(), &s3.GetBucketLocationInput{
158+
func _location(svc *s3.Client, bckName string) (string, error) {
159+
resp, err := svc.HeadBucket(context.Background(), &s3.HeadBucketInput{
148160
Bucket: aws.String(bckName),
149161
})
150162
if err != nil {
151-
return
163+
return "", err
152164
}
153-
region = string(resp.LocationConstraint)
154-
if region == "" {
155-
region = env.AwsDefaultRegion() // env "AWS_REGION" or "us-east-1" - in that order
165+
if resp.BucketRegion != nil && *resp.BucketRegion != "" {
166+
return *resp.BucketRegion, nil
156167
}
157-
return
168+
return env.AwsDefaultRegion(), nil // env "AWS_REGION" or "us-east-1" - in that order
158169
}
159170

160171
func _versioning(svc *s3.Client, bck *cmn.Bck) (enabled bool, errV error) {

0 commit comments

Comments
 (0)