awsretry

raw JSON →
1.0.2 verified Fri May 01 auth: no python

A decorator for AWS Boto3 calls that automatically retries on eventual consistency errors. Version 1.0.2 is current; release cadence is low (last release Apr 2019).

pip install awsretry
error AttributeError: module 'awsretry' has no attribute 'backoff'
cause Importing backoff directly instead of as a method on AWSRetry, or missing parentheses when calling the decorator.
fix
Use @AWSRetry.backoff() (with parentheses) to invoke the backoff factory. Incorrect: 'from awsretry import backoff; @backoff'.
error TypeError: 'module' object is not callable
cause Trying to call the backoff module directly without using the AWSRetry class.
fix
Correct usage: from awsretry import AWSRetry; @AWSRetry.backoff()
error botocore.exceptions.ClientError: An error occurred (404) when calling the ... operation: The specified ... does not exist.
cause The decorator only retries on specific error codes like 'Throttling' or 'RequestLimitExceeded'. For 404 errors (e.g., resource not found), it does not retry.
fix
Use a more general retry library (e.g., tenacity) or handle 404 separately.
gotcha The library only retries on specific error codes related to eventual consistency (e.g., 'Throttling', 'RequestLimitExceeded'). It does not retry on all boto3 exceptions.
fix If you need retry on other errors, consider using botocore's built-in retry mode or tenacity.
deprecated The library has not been updated since 2019. Boto3's built-in retry behavior (via botocore config) has improved significantly.
fix Prefer using botocore's retry configuration: boto3.client('ec2', config=Config(retries={'max_attempts': 10, 'mode': 'adaptive'}))
gotcha The decorator must be applied to a function that returns a boto3 service response directly; it does not support async functions.
fix Ensure decorated function is synchronous and returns a boto3 API call result.

Decorate a Boto3 call to retry on AWS eventual consistency errors.

import boto3
from awsretry import AWSRetry

@AWSRetry.backoff()
def describe_instance(instance_id):
    client = boto3.client('ec2', region_name='us-east-1')
    return client.describe_instances(InstanceIds=[instance_id])

describe_instance('i-12345678')