HTTP core functionality for AWS service clients in the AWS SDK for Kotlin, providing user agent management, retry policies, and HTTP middleware.
—
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.
The main retry policy class that implements AWS-specific retry logic with exponential backoff and jitter.
/**
* AWS-specific retry policy that extends StandardRetryPolicy with AWS service exception handling
*/
open class AwsRetryPolicy : StandardRetryPolicy() {
companion object {
/**
* The default retry policy instance used by AWS service clients
*/
val Default: AwsRetryPolicy
internal val knownErrorTypes: Map<String, RetryErrorType>
internal val knownStatusCodes: Map<Int, RetryErrorType>
}
/**
* Evaluates AWS-specific exceptions to determine retry behavior
* @param ex The exception to evaluate
* @return RetryDirective indicating whether to retry, or null to use default behavior
*/
protected override fun evaluateSpecificExceptions(ex: Throwable): RetryDirective?
}Usage Examples:
import aws.sdk.kotlin.runtime.http.retries.AwsRetryPolicy
// Use the default AWS retry policy
val retryPolicy = AwsRetryPolicy.Default
// Create a custom retry policy (extending AwsRetryPolicy)
class CustomAwsRetryPolicy : AwsRetryPolicy() {
protected override fun evaluateSpecificExceptions(ex: Throwable): RetryDirective? {
// Custom retry logic
return when (ex) {
is CustomServiceException -> RetryDirective.RetryError(RetryErrorType.Transient)
else -> super.evaluateSpecificExceptions(ex)
}
}
}
val customRetryPolicy = CustomAwsRetryPolicy()The retry policy integrates with the broader HTTP client infrastructure:
import aws.smithy.kotlin.runtime.http.request.HttpRequest
import aws.smithy.kotlin.runtime.http.response.HttpResponse
// Retry policies are typically configured at the service client level
// and work with the HTTP engine to handle transient failuresThe AWS retry policy recognizes specific error codes and HTTP status codes for intelligent retry handling:
// Error codes that indicate throttling (should be retried with backoff)
val throttlingErrors = mapOf(
"BandwidthLimitExceeded" to RetryErrorType.Throttling,
"EC2ThrottledException" to RetryErrorType.Throttling,
"LimitExceededException" to RetryErrorType.Throttling,
"PriorRequestNotComplete" to RetryErrorType.Throttling,
"ProvisionedThroughputExceededException" to RetryErrorType.Throttling,
"RequestLimitExceeded" to RetryErrorType.Throttling,
"RequestThrottled" to RetryErrorType.Throttling,
"RequestThrottledException" to RetryErrorType.Throttling,
"SlowDown" to RetryErrorType.Throttling,
"ThrottledException" to RetryErrorType.Throttling,
"Throttling" to RetryErrorType.Throttling,
"ThrottlingException" to RetryErrorType.Throttling,
"TooManyRequestsException" to RetryErrorType.Throttling,
"TransactionInProgressException" to RetryErrorType.Throttling
)// Error codes that indicate transient failures (should be retried)
val transientErrors = mapOf(
"IDPCommunicationError" to RetryErrorType.Transient,
"RequestTimeout" to RetryErrorType.Transient,
"RequestTimeoutException" to RetryErrorType.Transient
)// HTTP status codes that should trigger retries
val retryableStatusCodes = mapOf(
500 to RetryErrorType.Transient, // Internal Server Error
502 to RetryErrorType.Transient, // Bad Gateway
503 to RetryErrorType.Transient, // Service Unavailable
504 to RetryErrorType.Transient // Gateway Timeout
)Retry policies can be configured with various parameters:
Install with Tessl CLI
npx tessl i tessl/maven-aws-sdk-kotlin--aws-http-jvm