durable-execution-sdk-js.createretrystrategy.md

December 2, 2025 · View on GitHub

Home > @aws/durable-execution-sdk-js > createRetryStrategy

createRetryStrategy() function

Creates a retry strategy function with exponential backoff and configurable jitter

Signature:

createRetryStrategy: (config?: RetryStrategyConfig) =>
  (error: Error, attemptsMade: number) =>
    RetryDecision;

Parameters

Parameter

Type

Description

config

RetryStrategyConfig

(Optional) Configuration options for the retry strategy

Returns:

(error: Error, attemptsMade: number) => RetryDecision

A function that determines whether to retry and calculates delay based on error and attempt count

Remarks

The returned function takes an error and attempt count, and returns a RetryDecision indicating whether to retry and the delay before the next attempt.

**Delay Calculation:** - Base delay = initialDelay × backoffRate^(attemptsMade - 1) - Capped at maxDelay - Jitter applied based on jitter strategy - Final delay rounded to nearest second, minimum 1 second

**Error Filtering:** - If neither retryableErrors nor retryableErrorTypes is specified: all errors are retried - If either is specified: only matching errors are retried - If both are specified: errors matching either criteria are retried (OR logic)

Example

// Basic usage with defaults (retry all errors, 3 attempts, exponential backoff)
const defaultRetry = createRetryStrategy();

// Custom retry with more attempts and specific delays
const customRetry = createRetryStrategy({
  maxAttempts: 5,
  initialDelay: { seconds: 10 },
  maxDelay: { seconds: 60 },
  backoffRate: 2,
  jitter: JitterStrategy.HALF,
});

// Retry only specific error types
class TimeoutError extends Error {}
const typeBasedRetry = createRetryStrategy({
  retryableErrorTypes: [TimeoutError],
});

// Retry only errors matching message patterns
const patternBasedRetry = createRetryStrategy({
  retryableErrors: [/timeout/i, /connection/i, "rate limit"],
});

// Combine error types and patterns
const combinedRetry = createRetryStrategy({
  retryableErrorTypes: [TimeoutError],
  retryableErrors: [/network/i],
});

// Use in step configuration
await context.step(
  "api-call",
  async () => {
    return await callExternalAPI();
  },
  { retryStrategy: customRetry },
);