Build a Free-Tier Image Pipeline with Alibaba Cloud OSS + CDN
Every side project eventually hits the same wall: where do uploaded images live? Putting them on your app server bloats the disk, burns bandwidth, and makes backups painful. Object storage plus a CDN in front is the standard answer. This tutorial walks through the whole pipeline with Alibaba Cloud OSS and CDN — from bucket creation to a working upload endpoint — with cost numbers you can reason about.
Why object storage instead of the server disk
Object storage (OSS) is built for exactly this job:
- Pay per gigabyte stored and per request — no idle capacity
- Scale from 10 images to 10 million without touching infrastructure
- Integrates natively with a CDN for global edge delivery
- Your app server stays small and stateless
Step 1: Create a bucket
In the OSS console, create a bucket with these settings for a public-read, private-write pattern:
- Region: pick the one closest to your users (or the same region as your ECS instance to avoid cross-region traffic fees)
- Access control: private (we will generate signed URLs or use a CDN origin)
- Versioning: enable if images are user-generated and you want rollback safety
Step 2: Upload with the SDK
The Python SDK makes uploads a few lines:
import oss2
auth = oss2.Auth(access_key_id, access_key_secret)
bucket = oss2.Bucket(auth, endpoint, bucket_name)
bucket.put_object_from_file(
f"uploads/{uuid4().hex}.jpg",
"/tmp/source.jpg",
headers={"Content-Type": "image/jpeg"}
)
Never expose the access key to the browser. Upload from your backend, or use STS temporary credentials for client-side uploads — OSS supports both cleanly.
Step 3: Put a CDN in front
Direct OSS URLs work, but for repeated views a CDN saves money and improves latency:
- Create a CDN domain pointing at the OSS bucket as origin
- Enable image processing (resize, crop, webp conversion) — OSS Image Processing can transform images on the fly, so you store one original and serve many derivatives
- Set a reasonable cache TTL (7 days is fine for immutable content)
Step 4: What it costs
Rough order of magnitude for a hobby project:
- Storage: fractions of a cent per GB-month in standard tier
- CDN traffic: cheaper than server egress in most regions
- Requests: pennies per million in the standard tier
Exact pricing moves with region and tier, so check the official calculator before launch. The key insight is architectural: your app server stays at a fixed size no matter how viral your images go.
Production notes
- Validate uploads server-side: size limits, MIME whitelist, hash deduplication
- Use a lifecycle rule to move old originals to cold storage
- Log access via OSS logging or your CDN log service for abuse detection
If you are comparing storage options or need a reference architecture for your project, I keep an independent summary of current cloud deals and setup notes at lieke-ai.com. Alibaba Cloud's official campaign page with current coupons: Alibaba Cloud coupons.