Skip to content

Commit 89ef745

Browse files
committed
add a default retry strategy
1 parent be3c42a commit 89ef745

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

packages/core/src/shared/awsClientBuilderV3.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import { CredentialsShim } from '../auth/deprecated/loginManager'
77
import { AwsContext } from './awsContext'
8-
import { AwsCredentialIdentityProvider } from '@smithy/types'
8+
import { AwsCredentialIdentityProvider, RetryStrategyV2 } from '@smithy/types'
99
import { Client as IClient } from '@smithy/types'
1010
import { getUserAgent } from './telemetry/util'
1111
import { DevSettings } from './settings'
@@ -15,9 +15,11 @@ import {
1515
DeserializeMiddleware,
1616
HandlerExecutionContext,
1717
Provider,
18+
RetryStrategy,
1819
UserAgent,
1920
} from '@aws-sdk/types'
2021
import { HttpResponse } from '@aws-sdk/protocol-http'
22+
import { ConfiguredRetryStrategy } from '@smithy/util-retry'
2123
import { telemetry } from './telemetry'
2224
import { getRequestId, getTelemetryReason, getTelemetryReasonDesc, getTelemetryResult } from './errors'
2325
import { extensionVersion } from '.'
@@ -32,6 +34,7 @@ interface AwsConfigOptions {
3234
requestHandler: any
3335
apiVersion: string
3436
endpoint: string
37+
retryStrategy: RetryStrategy | RetryStrategyV2
3538
}
3639
export type AwsClientOptions = AwsConfigOptions
3740

@@ -73,6 +76,11 @@ export class DefaultAWSClientBuilderV3 implements AWSClientBuilderV3 {
7376
if (!opt.customUserAgent && userAgent) {
7477
opt.customUserAgent = [[getUserAgent({ includePlatform: true, includeClientId: true }), extensionVersion]]
7578
}
79+
80+
if (!opt.retryStrategy) {
81+
// Simple exponential backoff strategy as default.
82+
opt.retryStrategy = new ConfiguredRetryStrategy(5, (attempt: number) => 1000 * 2 ** attempt)
83+
}
7684
// TODO: add tests for refresh logic.
7785
opt.credentials = async () => {
7886
const creds = await shim.get()

0 commit comments

Comments
 (0)