From 4f9d36a9586623f0a49e2fa396d6cceab10790f6 Mon Sep 17 00:00:00 2001 From: Zeng Ming Date: Sat, 29 Jun 2019 00:08:19 +0800 Subject: [PATCH] Support custom endpoint for S3 (#1476) Signed-off-by: mizeng --- aws/dynamodb_storage_client.go | 4 +++- aws/s3_storage_client.go | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/aws/dynamodb_storage_client.go b/aws/dynamodb_storage_client.go index 872568c6bf3c..4810bf3cf60d 100644 --- a/aws/dynamodb_storage_client.go +++ b/aws/dynamodb_storage_client.go @@ -126,7 +126,8 @@ func (cfg *DynamoDBConfig) RegisterFlags(f *flag.FlagSet) { // StorageConfig specifies config for storing data on AWS. type StorageConfig struct { DynamoDBConfig - S3 flagext.URLValue + S3 flagext.URLValue + S3ForcePathStyle bool } // RegisterFlags adds the flags required to config this to the given FlagSet @@ -135,6 +136,7 @@ func (cfg *StorageConfig) RegisterFlags(f *flag.FlagSet) { f.Var(&cfg.S3, "s3.url", "S3 endpoint URL with escaped Key and Secret encoded. "+ "If only region is specified as a host, proper endpoint will be deduced. Use inmemory:/// to use a mock in-memory implementation.") + f.BoolVar(&cfg.S3ForcePathStyle, "s3.force-path-style", false, "Set this to `true` to force the request to use path-style addressing.") } type dynamoDBStorageClient struct { diff --git a/aws/s3_storage_client.go b/aws/s3_storage_client.go index 81a18254e8c8..dfb74a42584f 100644 --- a/aws/s3_storage_client.go +++ b/aws/s3_storage_client.go @@ -47,6 +47,8 @@ func NewS3ObjectClient(cfg StorageConfig, schemaCfg chunk.SchemaConfig) (chunk.O return nil, err } + s3Config = s3Config.WithS3ForcePathStyle(cfg.S3ForcePathStyle) // support for Path Style S3 url if has the flag + s3Config = s3Config.WithMaxRetries(0) // We do our own retries, so we can monitor them s3Client := s3.New(session.New(s3Config)) bucketName := strings.TrimPrefix(cfg.S3.URL.Path, "/")