Skip to content

Commit 95cfc15

Browse files
Merge pull request #30 from amadhusu/RHOAIENG-3774
UPSTREAM:<carry>:fix:Endpoint fix for AWS S3 Bucket Session
2 parents 3efe0f0 + 502e439 commit 95cfc15

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

backend/src/v2/objectstore/object_store.go

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -359,13 +359,23 @@ func createBucketSession(ctx context.Context, namespace string, sessionInfo *Ses
359359
if err != nil {
360360
return nil, err
361361
}
362-
sess, err := session.NewSession(&aws.Config{
363-
Credentials: creds,
364-
Region: aws.String(sessionInfo.Region),
365-
Endpoint: aws.String(sessionInfo.Endpoint),
366-
DisableSSL: aws.Bool(sessionInfo.DisableSSL),
367-
S3ForcePathStyle: aws.Bool(true),
368-
})
362+
config := &aws.Config{}
363+
config.Credentials = creds
364+
config.Region = aws.String(sessionInfo.Region)
365+
config.DisableSSL = aws.Bool(sessionInfo.DisableSSL)
366+
config.S3ForcePathStyle = aws.Bool(true)
367+
// AWS Specific:
368+
// Path-style S3 endpoints, which are commonly used, may fall into either of two subdomains:
369+
// 1) s3.amazonaws.com
370+
// 2) s3.<AWS Region>.amazonaws.com
371+
// for (1) the endpoint is not required, thus we skip it, otherwise the writer will fail to close due to region mismatch.
372+
// https://aws.amazon.com/blogs/infrastructure-and-automation/best-practices-for-using-amazon-s3-endpoints-in-aws-cloudformation-templates/
373+
// https://docs.aws.amazon.com/sdk-for-go/api/aws/session/
374+
awsEndpoint, _ := regexp.MatchString(`^(https://)?s3.amazonaws.com`, strings.ToLower(sessionInfo.Endpoint))
375+
if !awsEndpoint {
376+
config.Endpoint = aws.String(sessionInfo.Endpoint)
377+
}
378+
sess, err := session.NewSession(config)
369379
if err != nil {
370380
return nil, fmt.Errorf("Failed to create session to access minio: %v", err)
371381
}

0 commit comments

Comments
 (0)