Boto (AWS SDK v2)
Boto is the legacy Python SDK for Amazon Web Services (AWS), providing an object-oriented interface to AWS services. Its last release was 2.49.0 in 2017. The project is no longer actively maintained and has been superseded by `boto3`, which is the current official AWS SDK for Python.
Warnings
- breaking The `boto` library is officially abandoned and superseded by `boto3`. It is no longer maintained, receives no security updates, and may not be compatible with newer AWS API features or Python versions.
- gotcha `boto` was primarily designed for Python 2. While it might run with basic functionality on Python 3 (especially earlier Python 3 versions), it is not officially supported nor tested for Python 3 compatibility. Many functionalities may be broken or behave unexpectedly.
- gotcha `boto`'s authentication methods are older and less flexible than `boto3`. It often requires explicitly providing `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` directly or via environment variables, and has limited support for modern IAM roles, especially for EC2 instance profiles, compared to `boto3`'s default credential chain.
Install
-
pip install boto
Imports
- S3Connection
import boto.s3.connection; conn = boto.s3.connection.S3Connection(...)
Quickstart
import boto
import os
# Ensure AWS credentials are set as environment variables (recommended)
# For example: export AWS_ACCESS_KEY_ID='AKIA...'
# export AWS_SECRET_ACCESS_KEY='your_secret_key...'
# Boto 2 primarily supports Python 2, and while it might run on Python 3,
# boto3 is the recommended and actively maintained SDK for Python 3.
try:
# Connect to S3 using credentials from environment variables
# or explicitly provided arguments
conn = boto.connect_s3(
aws_access_key_id=os.environ.get('AWS_ACCESS_KEY_ID', 'YOUR_AWS_ACCESS_KEY_ID'),
aws_secret_access_key=os.environ.get('AWS_SECRET_ACCESS_KEY', 'YOUR_AWS_SECRET_ACCESS_KEY')
)
# List all buckets
print("Listing S3 buckets:")
buckets = conn.get_all_buckets()
if buckets:
for bucket in buckets:
print(f"- {bucket.name}")
else:
print("No S3 buckets found.")
except boto.exception.S3ResponseError as e:
print(f"S3 Error: {e.reason} - {e.error_code} - {e.message}")
print("Please check your AWS credentials and region settings.")
except Exception as e:
print(f"An unexpected error occurred: {e}")