diff --git a/readme.md b/readme.md index 8b45178..3bedf72 100644 --- a/readme.md +++ b/readme.md @@ -72,6 +72,19 @@ db.connect({ }) ``` +As an alternative, the internal retry behaviour of the AWS SDK can also be used by setting [`maxRetries`](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Config.html#maxRetries-property) and [`retryDelayOptions`](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Config.html#retryDelayOptions-property). + +```js +db.connect({ + maxRetries: 3, + retryDelayOptions: { base: 300 } +}) +``` + +As this setting is global, it cannot be overridden at the method level. + +Note that it may not advisable to use both `dynongo`'s retry logic and enable the AWS SDK retry behaviour at the same time. If both are enabled, the AWS SDK retry behaviour will trigger first and if the failure persists, the built-in logic inside `dynongo` will keep retrying the failing method. + #### DynamoDB Local It is possible to connect to a [local DynamoDB](http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Tools.DynamoDBLocal.html) database diff --git a/src/lib/dynamodb.ts b/src/lib/dynamodb.ts index 119812e..ef3ada7 100644 --- a/src/lib/dynamodb.ts +++ b/src/lib/dynamodb.ts @@ -27,6 +27,11 @@ export interface DynamoDBOptions { sessionToken?: string; retries?: number | RetryOptions; httpOptions?: AWS.HTTPOptions; + maxRetries?: number; + retryDelayOptions?: { + base?: number, + customBackoff?(retryCount: number, err: Error): number + }; } export class DynamoDB { @@ -47,7 +52,14 @@ export class DynamoDB { this._retries = configureRetryOptions(this.options.retries); - AWS.config.update(pick(this.options, ['region', 'accessKeyId', 'secretAccessKey', 'sessionToken'])); + AWS.config.update(pick(this.options, [ + 'region', + 'accessKeyId', + 'secretAccessKey', + 'sessionToken', + 'maxRetries', + 'retryDelayOptions' + ])); if (this.options.local) { // Starts dynamodb in local mode diff --git a/src/test/test.ts b/src/test/test.ts index d6f0de5..5e72737 100644 --- a/src/test/test.ts +++ b/src/test/test.ts @@ -34,6 +34,13 @@ test('connect options', t => { }); }); +test('connect with native retry options', t => { + db.connect({maxRetries: 5, retryDelayOptions: {base: 500}}); + + t.is(db.raw?.config.maxRetries, 5); + t.deepEqual(db.raw?.config.retryDelayOptions, {base: 500}); +}); + test('connect locally', t => { db.connect({local: true}); t.is((db.raw!).endpoint.href, 'http://localhost:8000/');