Sub topic 3
Objects, keys and prefixes
This chapter assumes you can run AWS CLI commands, read basic Python, and have a bucket to work in (see the previous chapter). It covers what an S3 object is, how keys name it, and how prefixes let you group and list objects.
What an object is
An object is the unit of storage in S3. It has four parts:
- Key: the object's name, unique within its bucket.
- Value: the bytes you stored. One object can hold from 0 bytes up to 5 TB.
- Metadata: name-value pairs, such as
Content-Type, plus any customx-amz-meta-*pairs you add. - Version ID: set only when versioning is on (a later chapter).
You can't edit part of an object in place. To change it, you write a whole new object under the same key.
Keys are flat names
A key is a string of up to 1,024 bytes of UTF-8. S3 has no real folders. The key reports/2026/report.csv is one string, and the slashes are ordinary characters.
The console shows folders because it splits keys on /. That is a display choice and not a storage structure.
Prefixes and listing
A prefix is the leading part of a key. Listing with Prefix="reports/" returns every key that starts with those characters.
You can also pass a delimiter, usually /. S3 then groups keys that share the next delimiter-bounded segment into CommonPrefixes. This gives you a folder-like view of one level.
Suppose the bucket holds these keys:
reports/2026/report.csvreports/2026/summary.csvreports/2025/report.csvlogs/app.log
import boto3
s3 = boto3.client("s3")
bucket = "my-example-bucket-123456789012"
response = s3.list_objects_v2(
Bucket=bucket,
Prefix="reports/",
Delimiter="/",
)
for p in response.get("CommonPrefixes", []):
print("prefix:", p["Prefix"])
for obj in response.get("Contents", []):
print("object:", obj["Key"])The output is prefix: reports/2025/ and prefix: reports/2026/. No objects print, because every key under reports/ sits one level deeper.
Listing limits and pagination
list_objects_v2 returns at most 1,000 keys per call. Results come back in UTF-8 binary order of the key. To read more, use a paginator:
import boto3
s3 = boto3.client("s3")
paginator = s3.get_paginator("list_objects_v2")
for page in paginator.paginate(Bucket="my-example-bucket-123456789012", Prefix="reports/"):
for obj in page.get("Contents", []):
print(obj["Key"], obj["Size"])Designing keys
Listing is the only query S3 gives you, and it works on key prefixes. So design keys around how you will list them.
- Put the part you filter by first.
logs/2026/11/26/app.loglets you list one day withlogs/2026/11/26/. - Use zero-padded numbers (
11, not1) so key order matches time order. - Avoid leading or trailing spaces and control characters, which are hard to handle in URLs and tools.
- Keys are case-sensitive:
Report.csvandreport.csvare different objects. - Don't rely on key order for throughput. S3 scales request rates per prefix, so spreading heavy traffic across several prefixes raises the total. A random-looking prefix is not required for normal workloads.
Some actions apply by prefix as well. Lifecycle rules, bucket policy conditions and replication filters can all target a prefix, so a clear layout makes those easier to write.
Renaming and moving
S3 has no rename. A "move" is a copy to the new key followed by a delete of the old one.
aws s3 mv s3://my-example-bucket-123456789012/reports/2026/report.csv \
s3://my-example-bucket-123456789012/archive/2026/report.csvThe mv command does both steps. Renaming a prefix means doing this for every key under it, so choose key layouts you won't need to change.
Exercise
A bucket holds photos/2026/01/a.jpg, photos/2026/02/b.jpg and photos/2025/12/c.jpg. Which list_objects_v2 arguments return only the prefixes photos/2026/01/ and photos/2026/02/, and why is there no real folder involved?
Show answer
Use Prefix="photos/2026/" and Delimiter="/". S3 returns those two strings in CommonPrefixes. Each key is a flat string, so S3 matches the leading characters and groups on the next / at request time, and nothing in the bucket is a folder.