Understanding Buckets, Objects and Keys in Amazon S3
This lesson introduces the S3 data model: buckets, objects, keys and prefixes, metadata, the ways objects are addressed, the core API operations, the default security settings and the pricing model. The later lessons in this module build on these ideas.
Learning outcomes
After completing this lesson, you will be able to:
- Explain how buckets, objects, keys and prefixes are related, and why S3 has no real folders.
- Describe the parts of an object, including system and user-defined metadata, and how each can be changed.
- Distinguish the URL, S3 URI and ARN forms of an object's name, and the bucket and object ARNs in a policy.
- Identify the core API operation for a task and the page limit that list operations apply.
- Describe the default security settings of a new bucket and the components of S3 pricing.
Buckets
Amazon Simple Storage Service (Amazon S3) is an object storage service. Unlike a file system, it has no directories, file handles or partial writes: an application stores and retrieves whole objects through an HTTPS API. A bucket is the container that holds objects, and every object belongs to exactly one bucket.
A bucket is created in one AWS Region, and its objects stay in that Region unless the developer copies or replicates them elsewhere. S3 stores each object redundantly across multiple Availability Zones in the Region, which gives the S3 Standard storage class its 99.999999999% (eleven nines) durability. Choosing the Region close to the users or the compute that reads the data reduces latency and data transfer cost, and it can also be required by data residency rules.
Bucket names for general purpose buckets are shared by all AWS accounts, so a name must be globally unique and cannot be changed after the bucket is created. A name is 3 to 63 characters long and contains only lowercase letters, numbers, hyphens and periods, because it becomes part of a DNS host name. An account can create up to 10,000 general purpose buckets by default. Because names are permanent and global, applications usually read the bucket name from configuration, such as an environment variable, rather than hard-coding it.
S3 also offers specialised bucket types, such as directory buckets for the S3 Express One Zone storage class. This module concentrates on general purpose buckets, which are the default and the type that most exam scenarios describe.
Objects and metadata
An object is the unit of storage. It consists of the following parts, which together describe the data and how it is stored.
- Key: the object's name, unique within the bucket, such as
invoices/2026/10/inv-1001.pdf. - Data: the content itself, from zero bytes up to 50 TB, as Managing Object Storage Classes, Lifecycle, Versioning and Replication explains.
- Metadata: name-value pairs that describe the object.
- Version ID: an identifier for each version, present when versioning is enabled on the bucket.
- Tags: up to 10 key-value pairs used for lifecycle filters, cost allocation and access conditions.
Objects are replaced, not edited. To change one byte of an object, the application uploads a complete new object under the same key, which overwrites the old one or, with versioning enabled, becomes the newest version. Workloads that need to update small parts of a record frequently are better suited to a database such as DynamoDB.
System and user-defined metadata
System-defined metadata is managed by S3 or set through standard HTTP headers. It includes Content-Type, which tells a browser how to display the object, Content-Length, Last-Modified and the ETag, a hash that changes whenever the content changes. User-defined metadata consists of custom headers whose names begin with x-amz-meta-, such as x-amz-meta-customer-id, limited to 2 KB in total. Metadata is fixed when the object is written; changing it later requires copying the object onto itself with new metadata. Tags, by contrast, can be changed at any time without rewriting the object.
Keys, prefixes and folders
S3 has a flat namespace. A key such as invoices/2026/10/inv-1001.pdf is a single string, and the slashes have no special meaning to the storage layer. The part of a key up to a chosen point, such as invoices/2026/, is called a prefix.
Prefixes give the appearance of folders. When a list request specifies a delimiter of /, S3 groups keys that share the next path segment and returns them as CommonPrefixes, and the S3 console uses this to display folders. Creating a folder in the console simply stores an empty object whose key ends in /. Deleting a folder therefore means deleting every object whose key begins with that prefix.
Although prefixes are only part of the key, many S3 features act on them, so a deliberate key design pays off. Lifecycle rules and event notifications can be filtered by prefix, IAM and bucket policies can grant access to arn:aws:s3:::bucket/prefix/*, and S3 scales request rates per prefix, as Scaling S3 Request Rates and Transfers explains.
Buckets, keys and folders
Addressing buckets and objects
The same object can be named in several ways, depending on whether a browser, the AWS CLI or a policy refers to it.
URLs
Applications and browsers reach an object through a virtual-hosted-style URL, in which the bucket name is part of the host name, such as https://customer-docs.s3.eu-west-1.amazonaws.com/invoices/inv-1001.pdf. The older path-style form, with the bucket name in the path, is being phased out. A URL only works for a caller who is allowed to read the object: either the request is signed with credentials that have permission, or it is a presigned URL, as Granting Temporary Uploads and Downloads with Presigned URLs explains.
S3 URIs and ARNs
The AWS CLI and many AWS services use the S3 URI form, s3://customer-docs/invoices/inv-1001.pdf. IAM and bucket policies use Amazon Resource Names (ARNs). An S3 ARN contains neither a Region nor an account ID, because bucket names are globally unique. The bucket and the objects in it are different resources: arn:aws:s3:::customer-docs is the bucket, used for actions such as s3:ListBucket, and arn:aws:s3:::customer-docs/* covers its objects, used for actions such as s3:GetObject. The following table summarises the three forms.
| Form | Example | Used by |
|---|---|---|
| Virtual-hosted-style URL | https://customer-docs.s3.eu-west-1.amazonaws.com/inv-1001.pdf | Browsers, HTTP clients and presigned URLs |
| S3 URI | s3://customer-docs/inv-1001.pdf | The AWS CLI and service configuration |
| ARN | arn:aws:s3:::customer-docs/inv-1001.pdf | IAM policies, bucket policies and event configuration |
Core API operations
A small set of API operations covers most application code. Each is described below, followed by an example.
Writing and reading objects
PutObject uploads an object in a single request, up to 5 GB; larger objects use multipart upload. GetObject downloads an object, and its Range header reads only part of it, such as the first megabyte of a large log file. HeadObject returns an object's metadata without its content, so it is the cheap way to check that an object exists or to read its size and Content-Type.
Listing objects
ListObjectsV2 returns the keys in a bucket, optionally limited to a prefix. Each response contains at most 1,000 keys. When more exist, the response sets IsTruncated and includes a NextContinuationToken, which the next request must pass to continue. SDK paginators handle this loop automatically.
Copying and deleting objects
CopyObject copies an object within S3 without downloading it, up to 5 GB in one request, and it is also the way to change an object's metadata. DeleteObject removes one object, and DeleteObjects removes up to 1,000 in one request. In a versioned bucket, a delete without a version ID adds a delete marker instead of removing data.
The following Python code uses these operations through the AWS SDK for Python (Boto3):
import boto3
s3 = boto3.client("s3")
bucket = "customer-docs"
s3.put_object(Bucket=bucket, Key="invoices/inv-1001.pdf", Body=pdf_bytes,
ContentType="application/pdf", Metadata={"customer-id": "C-1042"})
head = s3.head_object(Bucket=bucket, Key="invoices/inv-1001.pdf")
print(head["ContentLength"], head["Metadata"]) # {'customer-id': 'C-1042'}
paginator = s3.get_paginator("list_objects_v2")
for page in paginator.paginate(Bucket=bucket, Prefix="invoices/"):
for obj in page.get("Contents", []):
print(obj["Key"], obj["Size"])The following table summarises the operations.
| Operation | Purpose | Key limit or behaviour |
|---|---|---|
PutObject | Upload a whole object | Up to 5 GB per request |
GetObject | Download an object or a byte range | Range header for partial reads |
HeadObject | Read metadata only | No content is returned |
ListObjectsV2 | List keys, optionally by prefix | At most 1,000 keys per page |
CopyObject | Copy within S3 or replace metadata | Up to 5 GB per request |
DeleteObjects | Delete several objects | Up to 1,000 keys per request |
Choose the S3 operation
Default settings and pricing
A new general purpose bucket is secure by default, and the following list describes the settings it starts with. Protecting S3 Data with Access Controls and Encryption explains each one in depth.
- Private: only the owning account can access the bucket until a policy grants access to others.
- Block Public Access on: policies that would make the bucket public are rejected.
- ACLs disabled: the bucket owner owns every object, and access is controlled only by policies.
- Encrypted: every new object is encrypted at rest with SSE-S3.
- Versioning off: overwriting or deleting an object loses the previous data until versioning is enabled.
S3 charges for four things. Storage is billed per gigabyte-month at a rate that depends on the storage class. Requests are billed per thousand, and writes and lists (PUT, COPY, POST and LIST) cost more than reads. Data transfer out to the internet is billed per gigabyte, while data transfer in is free. Some storage classes also charge for retrieval. A design that lists a large bucket repeatedly or makes millions of small requests can therefore cost more in requests than in storage.
A report that stops at 1,000 invoices
A nightly Lambda function builds a report of every invoice in a bucket. It worked for months, but once the bucket passed 1,000 invoices the report always listed exactly 1,000, and no error was logged. The function contained this code:
response = s3.list_objects_v2(Bucket="customer-docs", Prefix="invoices/")
keys = [obj["Key"] for obj in response["Contents"]]A single ListObjectsV2 call returns at most 1,000 keys. The response also had IsTruncated set to true and a continuation token, which the code ignored. Using the paginator, as in the earlier example, makes the SDK request each page in turn until every key has been returned. The same pattern applies to most AWS list and scan operations, such as DynamoDB Scan and Query, which also return results in pages.
A script calls DeleteObject on the key reports/2025/ to delete a folder, but all the reports remain. Why, and what removes them?
Show answer
S3 has a flat namespace, so the folder is only a shared prefix, and deleting the key reports/2025/ removes at most an empty marker object. Every object whose key begins with the prefix must be deleted, for example by listing them and calling DeleteObjects for up to 1,000 keys at a time, or with a lifecycle rule for that prefix.
Exam Tips
Remember for the exam
- General purpose bucket names are globally unique, permanent and DNS-compatible; a bucket lives in one Region and its data stays there unless it is replicated.
- S3 has a flat namespace: folders are key prefixes, and lifecycle rules, notifications, policies and request-rate scaling all work on prefixes.
- Objects are replaced, not edited. Metadata is fixed at upload, and changing it needs a copy; tags can be changed at any time.
- The bucket ARN (
arn:aws:s3:::bucket) and the object ARN (arn:aws:s3:::bucket/*) are different resources in a policy. ListObjectsV2returns at most 1,000 keys per call; use a paginator or the continuation token.HeadObjectchecks existence and reads metadata without downloading the object, and aRangeGET reads part of an object.- New buckets are private, block public access, disable ACLs and encrypt objects with SSE-S3 by default.