botocore

1.42.77 · active · verified Fri Mar 27

botocore is the low-level, data-driven core of boto3 and the AWS CLI, providing a direct interface to Amazon Web Services APIs. It handles request signing (AWS Signature Version 4), credential resolution, retry logic, pagination, and service model loading. Current version is 1.42.77, released by Amazon Web Services. Releases are extremely frequent — often multiple times per week — tracking new and updated AWS service APIs. Most users interact with botocore indirectly via boto3, but direct use is common for fine-grained control, event hooks, custom credential providers, and low-overhead Lambda code.

Warnings

Install

Imports

Quickstart

Create a botocore session, build an S3 client using environment-variable credentials, and handle errors idiomatically by inspecting the structured error response.

import os
import botocore.session
from botocore.config import Config
from botocore.exceptions import ClientError, BotoCoreError

# Build session — credentials resolved from env, ~/.aws/credentials, or IAM role
session = botocore.session.get_session()

client = session.create_client(
    's3',
    region_name=os.environ.get('AWS_DEFAULT_REGION', 'us-east-1'),
    aws_access_key_id=os.environ.get('AWS_ACCESS_KEY_ID', ''),
    aws_secret_access_key=os.environ.get('AWS_SECRET_ACCESS_KEY', ''),
    config=Config(
        retries={'max_attempts': 5, 'mode': 'adaptive'},
        connect_timeout=5,
        read_timeout=10,
    ),
)

try:
    response = client.list_buckets()
    for bucket in response.get('Buckets', []):
        print(bucket['Name'])
except ClientError as e:
    # AWS service-side error — inspect the structured code, NOT the string message
    code = e.response['Error']['Code']
    msg  = e.response['Error']['Message']
    print(f'AWS error [{code}]: {msg}')
    if code == 'AccessDenied':
        raise PermissionError('Check IAM permissions') from e
except BotoCoreError as e:
    # Client-side error (bad config, network, credential resolution)
    print(f'botocore client error: {e}')
    raise

view raw JSON →