mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix(region): AWS buckets in us-east-1 have null location
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user