R2 Gateway: Cost-Controlled S3-Compatible Object Storage

· Tech · Cloudflare R2 / S3 API / Docker / Object Storage

Original language · English · 中文译文

R2 gateway architecture

My VPS has limited disk space, so I looked into object storage. Cloudflare R2 has a useful free tier, but it does not provide a direct, reliable switch that stops all usage at a billing threshold. Periodic checks through Workers still leave a gap.

I therefore built a small gateway in front of R2. The server uses the gateway's S3-compatible API instead of talking to R2 directly. The gateway counts each class of operation and blocks new requests as soon as a configured limit is reached.

The service runs in Docker so it can stay online continuously and move between hosts easily.

GitHub