From 475d5910e8d67dd4cff60ee3742ebf840a4aa601 Mon Sep 17 00:00:00 2001 From: Nicholas Watkins <5408930+rin1221@users.noreply.github.com> Date: Mon, 19 Mar 2018 14:53:23 -0500 Subject: [PATCH] Allow configuration of dynamodb storage to specify the max retries of aws sdk (#4115) --- physical/dynamodb/dynamodb.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/physical/dynamodb/dynamodb.go b/physical/dynamodb/dynamodb.go index bd12c47d4..eaa36afb0 100644 --- a/physical/dynamodb/dynamodb.go +++ b/physical/dynamodb/dynamodb.go @@ -183,6 +183,19 @@ func NewDynamoDBBackend(conf map[string]string, logger log.Logger) (physical.Bac } } + dynamodbMaxRetryString := os.Getenv("AWS_DYNAMODB_MAX_RETRIES") + if dynamodbMaxRetryString == "" { + dynamodbMaxRetryString = conf["dynamodb_max_retries"] + } + var dynamodbMaxRetry int = aws.UseServiceDefaultRetries + if dynamodbMaxRetryString != "" { + var err error + dynamodbMaxRetry, err = strconv.Atoi(dynamodbMaxRetryString) + if err != nil { + return nil, fmt.Errorf("invalid max retry: %s", dynamodbMaxRetryString) + } + } + credsConfig := &awsutil.CredentialsConfig{ AccessKey: accessKey, SecretKey: secretKey, @@ -202,7 +215,8 @@ func NewDynamoDBBackend(conf map[string]string, logger log.Logger) (physical.Bac WithEndpoint(endpoint). WithHTTPClient(&http.Client{ Transport: pooledTransport, - }) + }). + WithMaxRetries(dynamodbMaxRetry) client := dynamodb.New(session.New(awsConf)) if err := ensureTableExists(client, table, readCapacity, writeCapacity); err != nil {