Installation
boto3
pip install boto3Initialize Client
Python Example
import boto3
s3 = boto3.client(
's3',
endpoint_url='http://your-server-ip:3000',
aws_access_key_id='YOUR_ACCESS_KEY',
aws_secret_access_key='YOUR_SECRET_KEY',
region_name='us-east-1'
)Common Operations
Upload a File
# Upload from file
s3.upload_file('local-file.txt', 'my-bucket', 'remote-file.txt')
# Upload from bytes
s3.put_object(
Bucket='my-bucket',
Key='data.json',
Body=b'{"key": "value"}'
)Download a File
# Download to file
s3.download_file('my-bucket', 'remote-file.txt', 'local-file.txt')
# Get object content
response = s3.get_object(Bucket='my-bucket', Key='data.json')
content = response['Body'].read()List Objects
response = s3.list_objects_v2(Bucket='my-bucket')
for obj in response.get('Contents', []):
print(f"{obj['Key']} - {obj['Size']} bytes")Delete a File
s3.delete_object(Bucket='my-bucket', Key='file-to-delete.txt')