diff --git a/.changeset/red-coats-visit.md b/.changeset/red-coats-visit.md new file mode 100644 index 00000000000..dfd76288c20 --- /dev/null +++ b/.changeset/red-coats-visit.md @@ -0,0 +1,5 @@ +--- +"@smithy/credential-provider-imds": minor +--- + +The configuration maxRetries was changed to maxAttempts in middleware-retry to be compliant with other SDKs and retry strategy #1244. This change adds new configuration maxAttempts in RemoteProviderConfig and deprecates maxRetries. diff --git a/packages/credential-provider-imds/src/remoteProvider/RemoteProviderInit.spec.ts b/packages/credential-provider-imds/src/remoteProvider/RemoteProviderInit.spec.ts index c688dd5eb56..f12ebdd8c1f 100644 --- a/packages/credential-provider-imds/src/remoteProvider/RemoteProviderInit.spec.ts +++ b/packages/credential-provider-imds/src/remoteProvider/RemoteProviderInit.spec.ts @@ -17,4 +17,48 @@ describe("providerConfigFromInit", () => { maxRetries, }); }); + + it("should return maxAttempts with the same value as the deprecated maxRetries if maxAttempts is NOT provided", () => { + const timeout = 123456789; + const maxRetries = 987654321; + + expect(providerConfigFromInit({ timeout, maxRetries })).toEqual({ + timeout, + maxRetries, + maxAttempts: maxRetries, + }); + }); + + it("should return maxAttempts with the same value as maxAttempts option if it is provided", () => { + const timeout = 123456789; + const maxRetries = 987654321; + const maxAttempts = 987654322; + + expect(providerConfigFromInit({ timeout, maxRetries, maxAttempts })).toEqual({ + timeout, + maxRetries, + maxAttempts, + }); + }); + + it("should return maxAttempts with DEFAULT_MAX_RETRIES as value if both maxAttempts and maxRetries are NOT provided", () => { + const timeout = 123456789; + + expect(providerConfigFromInit({ timeout })).toEqual({ + timeout, + maxRetries: 0, + maxAttempts: 0, + }); + }); + + it("should return maxRetries with the same value as the new maxRetries maxAttempts if maxAttempts is provided with any value", () => { + const timeout = 123456789; + const maxAttempts = 987654321; + + expect(providerConfigFromInit({ timeout, maxAttempts })).toEqual({ + timeout, + maxRetries: maxAttempts, + maxAttempts, + }); + }); }); diff --git a/packages/credential-provider-imds/src/remoteProvider/RemoteProviderInit.ts b/packages/credential-provider-imds/src/remoteProvider/RemoteProviderInit.ts index a6b5751cfa8..b218649e03d 100644 --- a/packages/credential-provider-imds/src/remoteProvider/RemoteProviderInit.ts +++ b/packages/credential-provider-imds/src/remoteProvider/RemoteProviderInit.ts @@ -22,9 +22,15 @@ export interface RemoteProviderConfig { timeout: number; /** + * @deprecated The configuration maxRetries was changed to maxAttempts in middleware-retry to be compliant with other SDKs and retry strategy [#1244](https://github.com/aws/aws-sdk-js-v3/pull/1244). Use maxAttempts instead. * The maximum number of times the HTTP connection should be retried */ - maxRetries: number; + maxRetries?: number; + + /** + * The maximum number of times the HTTP connection should be retried + */ + maxAttempts?: number; } /** @@ -47,5 +53,14 @@ export interface RemoteProviderInit extends Partial { */ export const providerConfigFromInit = ({ maxRetries = DEFAULT_MAX_RETRIES, + maxAttempts, timeout = DEFAULT_TIMEOUT, -}: RemoteProviderInit): RemoteProviderConfig => ({ maxRetries, timeout }); +}: RemoteProviderInit): RemoteProviderConfig => { + const effectiveMaxAttempts = maxAttempts || maxRetries; + + return { + maxRetries: effectiveMaxAttempts, + maxAttempts: effectiveMaxAttempts, + timeout + }; +}