Learn Labs
Foundations

The S3 API

Buckets, keys, prefixes, metadata, multipart uploads, range reads, and presigned URLs

The S3 API is a few dozen HTTP operations. A handful of them cover almost everything applications do. labs/s3_basics.py exercises each against the cluster.

docker compose -f compose_prod.yaml run --rm labs python s3_basics.py

buckets: ['app-data', 'backups', 'drill', 'finance', 'probe', 'versioned']
head: 38 bytes, application/json metadata {'source': 'lab'} etag "e9892c47a54242a11c1db5ef165f7a90"
top level: ['invoices/'] ['during-master-failover', 'logo.png', 'report.txt', 'two-masters-down']
prefix invoices/2026/10/: ['invoices/2026/10/inv-1.json', 'invoices/2026/10/inv-2.json']
multipart: 3 parts, 24 MiB in 0.15s, etag "2f0c15edcb02835be145a1377cdfaa5c-3", intact=True
range read: 1024 bytes, matches: True
presigned GET with no credentials: {"key": "logo.png"}

Buckets and keys

A bucket is a namespace with its own settings (access, versioning, lifecycle). A key is any string up to 1,024 bytes. Inside a bucket, keys are just a flat, sorted list.

c.put_object(Bucket="app-data", Key="invoices/2026/10/inv-1.json",Body=data,ContentType="application/json",returned on GET, used by browsersMetadata={"source": "lab"})sent as x-amz-meta-sourcec.head_object(Bucket="app-data", Key="invoices/2026/10/inv-1.json")metadata only, no body

The ETag of a simple upload is the MD5 of the bytes, so clients can check integrity. Metadata is set at upload and can't be edited in place: to change it you copy the object onto itself with new metadata.

There are no folders

invoices/2026/10/inv-1.json is one key with slashes in it. Listing with a delimiter groups keys by the next /, which is how every S3 browser draws folders:

c.list_objects_v2(Bucket="app-data", Delimiter="/")CommonPrefixes: ['invoices/'] <- looks like a folderContents: ['logo.png', 'report.txt', ...] <- objects at the "top"c.list_objects_v2(Bucket="app-data", Prefix="invoices/2026/10/")Contents: inv-1.json, inv-2.json <- everything under that prefix

Listings return at most 1,000 keys per call; use a paginator. Design keys so the listings you need are prefix listings: tenant/42/uploads/... lets you list or delete one tenant's files; a random UUID as the whole key doesn't.

Multipart uploads

Large objects are uploaded in parts (5 MiB minimum except the last, up to 10,000 parts), in parallel and retryable one at a time:

mp = c.create_multipart_upload(Bucket="backups", Key="db/dump-1.bin")for n, off in enumerate(range(0, len(data), 8 * MiB), 1):r = c.upload_part(Bucket=..., Key=..., UploadId=mp["UploadId"],PartNumber=n, Body=data[off:off + 8 * MiB])parts.append({"PartNumber": n, "ETag": r["ETag"]})c.complete_multipart_upload(..., MultipartUpload={"Parts": parts})etag "2f0c15edcb02835be145a1377cdfaa5c-3" <- "-3": 3 parts, not an MD5 of the data

An upload that's started and never completed or aborted leaves its parts stored and invisible to normal listings. Add a lifecycle rule to abort incomplete uploads after a few days.

Range reads

Range: bytes=0-1023 returns just those bytes. Video players, Parquet readers and DuckDB depend on it to read the parts of a large object they need without downloading all of it.

Presigned URLs

A presigned URL is a normal URL with a signature and an expiry in its query string, computed locally from your secret key. Anyone holding it can do that one operation until it expires, with no credentials:

url = c.generate_presigned_url("get_object",
      Params={"Bucket": "app-data", "Key": "logo.png"}, ExpiresIn=60)
urllib.request.urlopen(url).read()     # {"key": "logo.png"}

This is how browsers upload and download directly to object storage without the bytes passing through your application servers: the app checks permissions, signs a URL for put_object or get_object, and hands it to the client.

Lab

  1. Run s3_basics.py. Then list app-data with the AWS CLI using --delimiter / and without it.
  2. Upload a 100 MB file with aws s3 cp and look at its ETag. How many parts did the CLI use?
  3. Generate a presigned URL with a 10-second expiry, wait 15 seconds, and fetch it. What error do you get?

On this page