惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园_首页
H
Help Net Security
量子位
The Cloudflare Blog
博客园 - Franky
博客园 - 聂微东
博客园 - 司徒正美
Last Week in AI
Last Week in AI
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Apple Machine Learning Research
Apple Machine Learning Research
宝玉的分享
宝玉的分享
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
有赞技术团队
有赞技术团队
罗磊的独立博客
GbyAI
GbyAI
雷峰网
雷峰网
T
The Blog of Author Tim Ferriss
Martin Fowler
Martin Fowler
S
SegmentFault 最新的问题
美团技术团队
阮一峰的网络日志
阮一峰的网络日志
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
U
Unit 42
MongoDB | Blog
MongoDB | Blog

OneUptime Blog

How to Monitor Azure App Services (PaaS) with OpenTelemetry Grafana Stack vs OneUptime: DIY Observability or Unified Platform? Your AI Workloads Are About to Blow Up Your Observability Bill The Great Observability Consolidation Is Here How to Write Custom Object Classes for Ceph How to Write Custom Ceph Manager Modules How to Write a ceph.conf Configuration File How to Use Rook-Ceph with OpenShift How to Use Rook-Ceph with Longhorn for Comparison How to Configure Volume Snapshot Class for RBD in Rook How to Configure VolumeReplicationClass Scheduling Intervals in Rook How to Set Up Volume Replication with Rook-Ceph How to Create Volume Group Snapshots with Rook CSI How to Visualize Ceph Network Performance in Grafana How to Enable Virtual Host-Style Bucket Access in Rook How to View Runtime Configuration via Admin Socket How to View Quota Settings and Update Stats in Ceph RGW How to View PG Scaling Recommendations with autoscale-status How to View PG Distribution via Admin Socket How to View Performance Metrics in the Ceph Dashboard How to View OSD Performance Counters in Ceph How to View Connection Status via Admin Socket How to View Ceph Cluster Summary Dashboard via CLI How to Version Control Rook-Ceph Configuration How to Version Control Ceph Infrastructure with Terraform How to Verify Kubernetes Node Requirements for Rook-Ceph Deployment How to Verify Health Before and After Rook Upgrades How to Verify Data Integrity with Deep Scrubbing How to Verify Complete Rook-Ceph Cleanup How to Verify Backup Integrity from Ceph Snapshots
How to Use boto3 (Python) with Ceph RGW S3
Nawaz Dhandala · 2026-03-31 · via OneUptime Blog

Overview

boto3 is the official AWS SDK for Python. By passing a custom endpoint_url and disabling SSL for development, you can use it to interact with Ceph RGW exactly as you would with AWS S3. This makes it easy to write Python applications that work against your on-premises Ceph cluster.

Install boto3

pip install boto3

Create a boto3 Session for Ceph

import boto3
from botocore.client import Config

s3 = boto3.client(
    "s3",
    endpoint_url="http://rook-ceph-rgw-my-store.rook-ceph:80",
    aws_access_key_id="myaccesskey",
    aws_secret_access_key="mysecretkey",
    region_name="us-east-1",
    config=Config(signature_version="s3v4", s3={"addressing_style": "path"}),
)

Bucket Operations

Create a bucket:

s3.create_bucket(Bucket="my-python-bucket")

List all buckets:

response = s3.list_buckets()
for bucket in response["Buckets"]:
    print(bucket["Name"])

Delete a bucket (must be empty):

s3.delete_bucket(Bucket="my-python-bucket")

Object Operations

Upload a file:

s3.upload_file(
    Filename="/tmp/data.json",
    Bucket="my-python-bucket",
    Key="data/data.json",
)

Upload from memory:

import json

data = {"key": "value", "count": 42}
s3.put_object(
    Bucket="my-python-bucket",
    Key="config/settings.json",
    Body=json.dumps(data),
    ContentType="application/json",
)

Download a file:

s3.download_file(
    Bucket="my-python-bucket",
    Key="data/data.json",
    Filename="/tmp/downloaded.json",
)

List objects in a bucket:

paginator = s3.get_paginator("list_objects_v2")
for page in paginator.paginate(Bucket="my-python-bucket", Prefix="data/"):
    for obj in page.get("Contents", []):
        print(obj["Key"], obj["Size"])

Generate a Presigned URL

url = s3.generate_presigned_url(
    ClientMethod="get_object",
    Params={"Bucket": "my-python-bucket", "Key": "data/data.json"},
    ExpiresIn=3600,
)
print(url)

Copy Objects

s3.copy_object(
    CopySource={"Bucket": "my-python-bucket", "Key": "data/data.json"},
    Bucket="my-python-bucket",
    Key="backup/data.json",
)

Error Handling

from botocore.exceptions import ClientError

try:
    s3.head_object(Bucket="my-python-bucket", Key="nonexistent.txt")
except ClientError as e:
    if e.response["Error"]["Code"] == "404":
        print("Object does not exist")
    else:
        raise

Summary

boto3 works transparently with Ceph RGW by specifying a custom endpoint_url and path-style addressing. All standard S3 operations are supported, making it easy to build Python applications that run against both AWS S3 and on-premises Ceph with minimal configuration changes.