0
# Retry Policies
1
2
AWS-specific retry policies that extend the standard retry policy with AWS service-specific exception handling, providing intelligent retry logic for transient failures and service throttling.
3
4
## Capabilities
5
6
### AwsRetryPolicy
7
8
The main retry policy class that implements AWS-specific retry logic with exponential backoff and jitter.
9
10
```kotlin { .api }
11
/**
12
* AWS-specific retry policy that extends StandardRetryPolicy with AWS service exception handling
13
*/
14
open class AwsRetryPolicy : StandardRetryPolicy() {
15
companion object {
16
/**
17
* The default retry policy instance used by AWS service clients
18
*/
19
val Default: AwsRetryPolicy
20
21
internal val knownErrorTypes: Map<String, RetryErrorType>
22
internal val knownStatusCodes: Map<Int, RetryErrorType>
23
}
24
25
/**
26
* Evaluates AWS-specific exceptions to determine retry behavior
27
* @param ex The exception to evaluate
28
* @return RetryDirective indicating whether to retry, or null to use default behavior
29
*/
30
protected override fun evaluateSpecificExceptions(ex: Throwable): RetryDirective?
31
}
32
```
33
34
**Usage Examples:**
35
36
```kotlin
37
import aws.sdk.kotlin.runtime.http.retries.AwsRetryPolicy
38
39
// Use the default AWS retry policy
40
val retryPolicy = AwsRetryPolicy.Default
41
42
// Create a custom retry policy (extending AwsRetryPolicy)
43
class CustomAwsRetryPolicy : AwsRetryPolicy() {
44
protected override fun evaluateSpecificExceptions(ex: Throwable): RetryDirective? {
45
// Custom retry logic
46
return when (ex) {
47
is CustomServiceException -> RetryDirective.RetryError(RetryErrorType.Transient)
48
else -> super.evaluateSpecificExceptions(ex)
49
}
50
}
51
}
52
53
val customRetryPolicy = CustomAwsRetryPolicy()
54
```
55
56
## Integration with HTTP Client
57
58
The retry policy integrates with the broader HTTP client infrastructure:
59
60
```kotlin
61
import aws.smithy.kotlin.runtime.http.request.HttpRequest
62
import aws.smithy.kotlin.runtime.http.response.HttpResponse
63
64
// Retry policies are typically configured at the service client level
65
// and work with the HTTP engine to handle transient failures
66
```
67
68
## Known Error Types
69
70
The AWS retry policy recognizes specific error codes and HTTP status codes for intelligent retry handling:
71
72
### Throttling Errors
73
```kotlin { .api }
74
// Error codes that indicate throttling (should be retried with backoff)
75
val throttlingErrors = mapOf(
76
"BandwidthLimitExceeded" to RetryErrorType.Throttling,
77
"EC2ThrottledException" to RetryErrorType.Throttling,
78
"LimitExceededException" to RetryErrorType.Throttling,
79
"PriorRequestNotComplete" to RetryErrorType.Throttling,
80
"ProvisionedThroughputExceededException" to RetryErrorType.Throttling,
81
"RequestLimitExceeded" to RetryErrorType.Throttling,
82
"RequestThrottled" to RetryErrorType.Throttling,
83
"RequestThrottledException" to RetryErrorType.Throttling,
84
"SlowDown" to RetryErrorType.Throttling,
85
"ThrottledException" to RetryErrorType.Throttling,
86
"Throttling" to RetryErrorType.Throttling,
87
"ThrottlingException" to RetryErrorType.Throttling,
88
"TooManyRequestsException" to RetryErrorType.Throttling,
89
"TransactionInProgressException" to RetryErrorType.Throttling
90
)
91
```
92
93
### Transient Errors
94
```kotlin { .api }
95
// Error codes that indicate transient failures (should be retried)
96
val transientErrors = mapOf(
97
"IDPCommunicationError" to RetryErrorType.Transient,
98
"RequestTimeout" to RetryErrorType.Transient,
99
"RequestTimeoutException" to RetryErrorType.Transient
100
)
101
```
102
103
### HTTP Status Codes
104
```kotlin { .api }
105
// HTTP status codes that should trigger retries
106
val retryableStatusCodes = mapOf(
107
500 to RetryErrorType.Transient, // Internal Server Error
108
502 to RetryErrorType.Transient, // Bad Gateway
109
503 to RetryErrorType.Transient, // Service Unavailable
110
504 to RetryErrorType.Transient // Gateway Timeout
111
)
112
```
113
114
## Configuration
115
116
Retry policies can be configured with various parameters:
117
118
- **Maximum Attempts**: Total number of retry attempts (including initial request)
119
- **Base Delay**: Initial delay before first retry attempt
120
- **Maximum Delay**: Cap on exponential backoff delay
121
- **Jitter**: Randomization to prevent thundering herd problems
122
- **Backoff Strategy**: Exponential, linear, or custom backoff algorithms