What you'll learn
Prefixfilters keys by their start;Delimitergroups the rest intoCommonPrefixes— the “folders”.- Each
ListObjectsV2page has up to 1,000 keys; followNextContinuationTokenuntilIsTruncatedis false. - Listing is for browsing and batch jobs, not lookups: if you know the key, GET it directly.
Section 01
Prefix and delimiter
Prefix keeps only keys that start with that string. Delimiter (usually /) tells S3 to roll up everything after the next delimiter into a CommonPrefixes entry, so one level at a time looks like a folder listing.
A prefix is plain string matching. sprites/grass also matches sprites/grass-old/… — end it with the delimiter when you mean one folder.
Try it · Prefix explorer
14 objects in the bucket. There are no folders — only keys, and the listing groups them for you.
new ListObjectsV2Command({ Bucket: "hoenn-pokedex-media", Prefix: "sprites/", Delimiter: "/" })CommonPrefixes (4)
Contents (0)
- No keys match directly.
Click a common prefix to “open” it. Compare sprites/grass with sprites/grass/: a prefix is a plain string match.
Section 02
Pages of 1,000
Keys come back in UTF-8 binary order, up to 1,000 per response (MaxKeys can lower that, never raise it). When there are more, IsTruncated is true and NextContinuationToken tells S3 where to resume.
import { paginateListObjectsV2 } from "@aws-sdk/client-s3";
const keys = [];
for await (const page of paginateListObjectsV2(
{ client },
{ Bucket: "hoenn-pokedex-media", Prefix: "sprites/grass/" }
)) {
for (const obj of page.Contents ?? []) keys.push(obj.Key);
}Section 03
Prefixes and throughput
S3 supports at least 3,500 PUT/COPY/POST/DELETE and 5,500 GET/HEAD requests per second per partitioned prefix, and there's no limit on the number of prefixes. If traffic grows suddenly S3 may answer 503 SlowDown while it scales; the SDK retries with backoff.
You rarely need to design for this at Pokédex scale, but spreading hot data over several prefixes is the lever when you do (Quest 12).
Practice
Your turn
List every grass-type sprite. There are more than 1,000, so a single ListObjectsV2 call won't return them all. Scope the listing with a prefix and keep asking for the next page until S3 says there are no more.
Prefix: "sprites/grass/", pass ContinuationToken, and loop on NextContinuationToken.Check
Check your understanding
Quick Quiz · one question, as many tries as you need.
ListObjectsV2 with Prefix: "sprites/" and Delimiter: "/". Where does sprites/grass/0252-treecko.png appear?Choose one answer.