diff --git a/pkg/storage/s3.go b/pkg/storage/s3.go index 1239bb4c4..a764c30c8 100644 --- a/pkg/storage/s3.go +++ b/pkg/storage/s3.go @@ -130,9 +130,6 @@ type S3BackendOptions struct { // Apply apply s3 options on backup.S3. func (options *S3BackendOptions) Apply(s3 *backup.S3) error { - if options.Region == "" { - options.Region = "us-east-1" - } if options.Endpoint != "" { u, err := url.Parse(options.Endpoint) if err != nil { @@ -176,10 +173,11 @@ func defineS3Flags(flags *pflag.FlagSet) { // TODO: remove experimental tag if it's stable flags.String(s3EndpointOption, "", "(experimental) Set the S3 endpoint URL, please specify the http or https scheme explicitly") - flags.String(s3RegionOption, "", "(experimental) Set the S3 region, e.g. us-east-1") + flags.String(s3RegionOption, "", "(experimental) Set the S3 region, e.g. us-east-1, "+ + "defaults to using the AWS_REGION env var") flags.String(s3StorageClassOption, "", "(experimental) Set the S3 storage class, e.g. STANDARD") flags.String(s3SseOption, "", "Set S3 server-side encryption, e.g. aws:kms") - flags.String(s3SseKmsKeyIDOption, "", "KMS CMK key id to use with S3 server-side encryption."+ + flags.String(s3SseKmsKeyIDOption, "", "KMS CMK key id to use with S3 server-side encryption. "+ "Leave empty to use S3 owned key.") flags.String(s3ACLOption, "", "(experimental) Set the S3 canned ACLs, e.g. authenticated-read") flags.String(s3ProviderOption, "", "(experimental) Set the S3 provider, e.g. aws, alibaba, ceph") @@ -228,8 +226,10 @@ func NewS3Storage( // revive:disable-line:flag-parameter qs := *backend awsConfig := aws.NewConfig(). WithMaxRetries(maxRetries). - WithS3ForcePathStyle(qs.ForcePathStyle). - WithRegion(qs.Region) + WithS3ForcePathStyle(qs.ForcePathStyle) + if qs.Region != "" { + awsConfig.WithRegion(qs.Region) + } if qs.Endpoint != "" { awsConfig.WithEndpoint(qs.Endpoint) } diff --git a/pkg/storage/s3_test.go b/pkg/storage/s3_test.go index 07715e311..41461ef35 100644 --- a/pkg/storage/s3_test.go +++ b/pkg/storage/s3_test.go @@ -109,7 +109,7 @@ func (r *testStorageSuite) TestApplyUpdate(c *C) { Endpoint: "", }, s3: &backup.S3{ - Region: "us-east-1", + Region: "", Bucket: "bucket", Prefix: "prefix", }, @@ -131,7 +131,7 @@ func (r *testStorageSuite) TestApplyUpdate(c *C) { Endpoint: "https://s3.us-west-2", }, s3: &backup.S3{ - Region: "us-east-1", + Region: "", Endpoint: "https://s3.us-west-2", Bucket: "bucket", Prefix: "prefix", @@ -143,7 +143,7 @@ func (r *testStorageSuite) TestApplyUpdate(c *C) { Endpoint: "http://s3.us-west-2", }, s3: &backup.S3{ - Region: "us-east-1", + Region: "", Endpoint: "http://s3.us-west-2", Bucket: "bucket", Prefix: "prefix",