From 029d2fa27ef1b19838af071c8c2e59a61fe09e22 Mon Sep 17 00:00:00 2001 From: Qiu Jian Date: Thu, 14 Jan 2021 03:59:36 +0800 Subject: [PATCH] fix(region): AWS buckets in us-east-1 have null location --- pkg/multicloud/aws/aws.go | 7 +++++++ pkg/multicloud/aws/region.go | 7 +++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/pkg/multicloud/aws/aws.go b/pkg/multicloud/aws/aws.go index 36216084ac..7e54eb8257 100644 --- a/pkg/multicloud/aws/aws.go +++ b/pkg/multicloud/aws/aws.go @@ -54,6 +54,8 @@ const ( AWS_GLOBAL_ARN_PREFIX = "arn:aws:iam::aws:policy/" AWS_CHINA_ARN_PREFIX = "arn:aws-cn:iam::aws:policy/" + + DEFAULT_S3_REGION_ID = "us-east-1" ) var ( @@ -313,6 +315,11 @@ func (client *SAwsClient) fetchBuckets() error { } location := *output.LocationConstraint + if len(location) == 0 { + // https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetBucketLocation.html + // Buckets in Region us-east-1 have a LocationConstraint of null. + location = DEFAULT_S3_REGION_ID + } region, err := client.getIRegionByRegionId(location) if err != nil { log.Errorf("client.getIRegionByRegionId %s fail %s", location, err) diff --git a/pkg/multicloud/aws/region.go b/pkg/multicloud/aws/region.go index 5c63f5718c..cdfeaf20eb 100644 --- a/pkg/multicloud/aws/region.go +++ b/pkg/multicloud/aws/region.go @@ -990,8 +990,11 @@ func (region *SRegion) CreateIBucket(name string, storageClassStr string, acl st } input := &s3.CreateBucketInput{} input.SetBucket(name) - input.CreateBucketConfiguration = &s3.CreateBucketConfiguration{} - input.CreateBucketConfiguration.SetLocationConstraint(region.GetId()) + if region.GetId() != DEFAULT_S3_REGION_ID { + location := region.GetId() + input.CreateBucketConfiguration = &s3.CreateBucketConfiguration{} + input.CreateBucketConfiguration.SetLocationConstraint(location) + } _, err = s3cli.CreateBucket(input) if err != nil { return errors.Wrap(err, "CreateBucket")