Registry / aws / aws-error-utils

aws-error-utils

JSON →
library2.7.0pypypi✓ verified 85d ago

AWS Error Utils is a Python library that provides error-handling functions to simplify dealing with `botocore.exceptions.ClientError` in boto3 applications. It aims to make AWS service exception handling more Pythonic by allowing direct matching against error codes and operation names, reducing the need to parse nested dictionary structures. The current version is 2.7.0, and it maintains a steady release cadence with minor updates addressing Python version support and new features.

pip install aws-error-utils
INSTALL
IMPORT
SIG · AWS-ERROR-UTILS
A
aws-error-utils
awspythonv2.7.0
Install
3.0s avg
Import
64ms
Disk
47MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.7.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.066s · 48.7MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 3.0s · import 0.061s · 49MB
47MB installed
● package 47MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

catch_aws_error
from aws_error_utils import catch_aws_error
errors
from aws_error_utils import errors
from aws_error_utils.errors import NoSuchBucket
The 'errors' object is imported directly, and its attributes (e.g., `errors.NoSuchBucket`) are aliases to `catch_aws_error()` calls, not actual exception classes.
aws_error_matches
from aws_error_utils import aws_error_matches
get_aws_error_info
from aws_error_utils import get_aws_error_info

This quickstart demonstrates how to use `catch_aws_error` to handle specific AWS `ClientError` exceptions. It attempts to access a non-existent S3 bucket, which typically raises a `NoSuchBucket` error. It also shows the alternative `errors.NoSuchBucket` syntax, which is an alias for `catch_aws_error('NoSuchBucket')`.

import boto3 from aws_error_utils import catch_aws_error, errors import os from botocore.exceptions import ClientError # Configure boto3 client with dummy credentials for local testing, or load from environment s3_client = boto3.client( 's3', aws_access_key_id=os.environ.get('AWS_ACCESS_KEY_ID', 'test'), aws_secret_access_key=os.environ.get('AWS_SECRET_ACCESS_KEY', 'test'), aws_session_token=os.environ.get('AWS_SESSION_TOKEN'), # Optional region_name=os.environ.get('AWS_DEFAULT_REGION', 'us-east-1') ) non_existent_bucket = "non-existent-aws-error-utils-test-bucket-12345" print(f"Attempting to list objects in '{non_existent_bucket}'...") try: s3_client.list_objects_v2(Bucket=non_existent_bucket) except catch_aws_error("NoSuchBucket") as e: print(f"Caught expected AWS error using catch_aws_error: Code={e.code}, Message='{e.message}'") except ClientError as e: print(f"Caught an unexpected ClientError: {e}") except Exception as e: print(f"Caught a generic exception: {e}") print("\nDemonstrating 'errors' class for common error codes (if applicable) (alias to catch_aws_error)...") try: s3_client.list_objects_v2(Bucket=non_existent_bucket) except errors.NoSuchBucket as e: print(f"Caught expected AWS error using errors.NoSuchBucket: Code={e.code}, Message='{e.message}'") except ClientError as e: print(f"Caught an unexpected ClientError via ClientError: {e}")
Debug
Known issues
breakingPython 3.6 support was removed in version 2.7. Users on Python 3.6 or earlier must upgrade their Python version or use an older version of `aws-error-utils`.
fix
Upgrade Python to 3.7 or higher. If upgrading Python is not feasible, pin `aws-error-utils<2.7.0`.
affects: >=2.7.0
breakingPython 3.5 support was removed in version 2.4.
fix
Upgrade Python to 3.6 or higher. If upgrading Python is not feasible, pin `aws-error-utils<2.4.0`.
affects: >=2.4.0
gotchaThe `errors` class (e.g., `errors.NoSuchBucket`) provides a simpler syntax but is limited to error codes that can be valid Python property names. For complex error codes (e.g., `InvalidInstanceID.NotFound`), you must use the `catch_aws_error()` function directly with the full string code.
fix
For error codes containing special characters or periods, always use `except catch_aws_error('Complex.ErrorCode'):` instead of `except errors.ComplexErrorCode:`.
affects: All
gotcha`errors.SomeError` is an alias for `catch_aws_error('SomeError')`, not an actual exception class. This means you cannot subclass `errors.SomeError` or use it in `issubclass()` checks.
fix
Treat `errors.SomeError` as a convenience function call within an `except` block rather than a standard Python exception class.
affects: All
gotchaWhen using `catch_aws_error()`, you must provide an error code. To match an exception exclusively by its `operation_name` (e.g., for all errors from a specific API call), you need to use `aws_error_utils.ALL_CODES` as the error code argument.
fix
Use `except catch_aws_error(aws_error_utils.ALL_CODES, operation_name='GetObject'):` to match all errors from the 'GetObject' operation.
affects: All
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'aws_error_utils'
The 'aws-error-utils' package is not installed in the Python environment.
fix
Install the package using pip: 'pip install aws-error-utils'.
ImportError: cannot import name 'is_s3express_bucket' from 'botocore.utils'
A version mismatch between 'boto3' and 'botocore' libraries.
fix
Ensure compatible versions of 'boto3' and 'botocore' are installed by updating both: 'pip install --upgrade boto3 botocore'.
ImportError: cannot import name 'safe_join'
The 'safe_join' function has been removed or relocated in the library being imported.
fix
Check the library's documentation for the updated import path or alternative functions.
ImportError: cannot import name 'process_tweet' from 'utils'
The 'utils' module does not contain a 'process_tweet' function, possibly due to a missing or incorrect import.
fix
Verify that the 'utils' module is correctly implemented and contains the 'process_tweet' function.
ImportError: cannot import name 'display'
A circular import or incorrect import statement in the code.
fix
Rearrange the import statements to avoid circular dependencies or import errors.
Upgrade
Version history
2.7.0latest on PyPI · released Nov 3, 2022
Audit
Dependencies
boto3requiredThe library is designed to work with exceptions raised by boto3/botocore.
Agent activity
20 hits · last 30 days
node
18
Resources