@@ -359,13 +359,23 @@ func createBucketSession(ctx context.Context, namespace string, sessionInfo *Ses
359
359
if err != nil {
360
360
return nil , err
361
361
}
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 )
369
379
if err != nil {
370
380
return nil , fmt .Errorf ("Failed to create session to access minio: %v" , err )
371
381
}
0 commit comments