Amazon S3 listing directories
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Amazon S3 does not have real directories. It stores objects in a flat namespace, and what looks like folders in the console is just object-key naming plus API parameters such as Prefix and Delimiter.
How S3 Simulates Directories
An S3 object key can contain slashes:
S3 treats those keys as plain strings. The slash is meaningful only because tools and APIs use it as a visual separator.
That means a "directory listing" in S3 is really a filtered prefix query.
Listing Prefixes with the AWS CLI
To inspect objects under a path-like prefix:
This produces a folder-style listing because the CLI is formatting keys for you. Under the hood, it is still querying objects by prefix.
If you want to see raw API-style information, use s3api:
The --delimiter / option tells S3 to group deeper keys into CommonPrefixes, which is the closest thing S3 has to subdirectories.
Listing from Python with boto3
You can do the same thing programmatically:
This separates "subdirectories" from objects directly under the prefix.
What Prefix and Delimiter Actually Do
These two parameters are the key to understanding S3 listings:
- '
Prefixlimits results to keys that start with a given string' - '
Delimiterasks S3 to collapse deeper matches into grouped prefixes'
Without a delimiter, S3 returns every matching object recursively. With Delimiter="/", you get one logical level at a time.
Empty Folders Are Not Real Objects
Another common surprise is that an empty folder does not really exist in S3 unless someone created a placeholder object such as photos/2026/. The S3 console may show a folder UI, but the underlying storage is still just keys.
That matters when applications expect filesystem behavior. If no object exists under a prefix, there is nothing for S3 to list.
This is also why deleting the last object under a prefix can make a "directory" disappear from the console. Nothing about the bucket hierarchy changed, because there was never a real directory entry to begin with.
Performance and Pagination
Large prefixes can require pagination. If you have many objects, keep following the continuation token:
That pattern is important for real buckets with large result sets.
It is also a reminder that S3 listings are API operations over objects, not filesystem reads. The more keys you ask S3 to examine, the more important prefix design becomes for both latency and cost.
Common Pitfalls
- Assuming S3 directories are real filesystem directories.
- Forgetting
Delimiter="/"and then wondering why the listing is recursive. - Expecting an empty folder to exist when no placeholder object was created.
- Ignoring pagination on large prefixes and accidentally reading only the first page.
Summary
- S3 is flat object storage, not a hierarchical filesystem.
- Folder-like behavior comes from object-key prefixes plus the delimiter parameter.
- Use
list_objects_v2withPrefixandDelimiter="/"for one-level folder listings. - The AWS CLI hides some of this complexity, but the underlying model is still key-based.
- Understanding prefixes is the main step to understanding S3 directory listings.

