Socket
Socket
Sign inDemoInstall

@smithy/util-retry

Package Overview
Dependencies
3
Maintainers
2
Versions
22
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @smithy/util-retry

Shared retry utilities to be used in middleware packages.


Version published
Weekly downloads
10M
decreased by-0.44%
Maintainers
2
Install size
388 kB
Created
Weekly downloads
 

Readme

Source

@smithy/util-retry

NPM version NPM downloads

This package provides shared utilities for retries.

Usage

Default

By default, each client already has a default retry strategy. The default retry count is 3, and only retryable errors will be retried.

AWS Documentation: Retry behavior.

import { S3Client } from "@aws-sdk/client-s3";

const client = new S3Client({}); // default retry strategy included.

MaxAttempts

If you want to change the number of attempts, you can provide maxAttempts configuration during client creation.

import { S3Client } from "@aws-sdk/client-s3";

const client = new S3Client({ maxAttempts: 4 });

This is recommended because the StandardRetryStrategy includes backoff calculation, deciding whether an error should be retried, and a retry token counter.

MaxAttempts and BackoffComputation

If you want to change the number of attempts and use a custom delay computation, you can use the ConfiguredRetryStrategy from @smithy/util-retry.

import { S3Client } from "@aws-sdk/client-s3";
import { ConfiguredRetryStrategy } from "@smithy/util-retry";

const client = new S3Client({
  retryStrategy: new ConfiguredRetryStrategy(
    4, // max attempts.
    (attempt: number) => 100 + attempt * 1000 // backoff function.
  ),
});

This example sets the backoff at 100ms plus 1s per attempt.

MaxAttempts and RetryStrategy

If you provide both maxAttempts and retryStrategy, the retryStrategy will get precedence as it's more specific.

import { S3Client } from "@aws-sdk/client-s3";
import { ConfiguredRetryStrategy } from "@smithy/util-retry";

const client = new S3Client({
  maxAttempts: 2, // ignored.
  retryStrategy: new ConfiguredRetryStrategy(
    4, // used.
    (attempt: number) => 100 + attempt * 1000 // backoff function.
  ),
});

Further customization

You can implement the RetryStrategyV2 interface.

Source: https://github.com/awslabs/smithy-typescript/blob/main/packages/types/src/retry.ts API Docs: https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-smithy-types/Interface/RetryStrategyV2/

Keywords

FAQs

Last updated on 14 Mar 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc