By the end you'll know
- What buckets, objects and keys are, why every bucket name in the world is different, and why S3 has no real folders
- The everyday commands for buckets and files, and when to use
aws s3oraws s3api - What a new bucket blocks and encrypts without being asked
- The ways to let someone read a file, and the one that works for sharing: a presigned link
- How S3 serves a static website, what it needs, and why CloudFront is usually the better way
- How versioning turns a delete into something you can undo, the commands for it, and what it costs
- The storage classes, what each costs, and the catches: minimum durations, retrieval fees, and waiting
- How lifecycle rules move and delete files on a schedule
Before you start
- You need: the
juniper-ryeprofile from Lesson 4, signed in. Lesson 3's IAM policies come back here, so skim them if they've faded. - The script:
s3-lab.shfrom the practice folder'slesson-15. Everything it creates is namedjr-lesson15-*, and itsdeletestep removes it. - How the script talks to AWS: only through the AWS CLI. The few lines of Python in it just turn the CLI's JSON into readable tables and never connect to AWS; boto3, AWS's Python library, comes in Lesson 20.
- To see every call the script makes, put
SHOW=1in front of any step, such asSHOW=1 ./s3-lab.sh perms. The lesson's "By hand" section lists them all too. - Where you run things: your own machine, labeled (Your machine).
- Every output below is from real runs on November 10, 2026. The
namesandwebsitesteps are from later runs, so their buckets have different names.
A public bucket is the classic AWS leak
Most cloud data leaks in the news were an S3 bucket someone made public, usually to share one file quickly. New buckets block that by default, and this lesson shows the block working. Leave it on. To share a file, use a presigned link, which this lesson also shows.
The short version
- A bucket holds objects; an object is a file plus its key, its name. Slashes in keys look like folders, but they're just part of the name.
- New buckets block public access, encrypt everything and turn off ACLs (access control lists), without being asked.
- To share one file, make a presigned link: it carries your permission, for as long as you choose, up to your own sign-in's expiry.
- Versioning keeps every version, so a delete only adds a marker you can remove. Every version is billed.
- Storage classes trade price for access: cheaper to keep, but minimum durations, retrieval fees and, for the archive classes, hours of waiting. Lifecycle rules move files between them on a schedule.
What this lesson costs
| Part | Cost |
|---|---|
| A bucket, its settings and its policies | $0 |
| Storing a dozen files under 100 bytes each | A tiny fraction of a cent |
| A few hundred requests | $0.005 per 1,000 uploads and lists; $0.0004 per 1,000 downloads |
| Minimum charges on the Standard-IA and Glacier Instant Retrieval files | Billed as 128 KB for 30 and 90 days, even after delete: still a tiny fraction of a cent |
| This lesson | Well under 1 cent, from credits |
What S3 is
S3 (Simple Storage Service) stores files, as many as you like, of up to 5 TB each, and hands them back over HTTPS. It's where Lesson 14's page lived, and where backups, logs, data for analysis, and the code for Lambda functions all end up later in the track.
| Part | What it is | In the bakery |
|---|---|---|
| Bucket | A container, in one Region, with a name no other AWS account in the world is using | jr-lesson15-b1278e; the random ending makes the name unique |
| Object | One file, plus metadata about it | A recipe, an order export, a photo |
| Key | The object's full name within the bucket | orders/2026/11/10.csv |
| Prefix | The start of a key, used like a folder | orders/ |
| Storage class | How the object is stored, and so what it costs | Standard, unless you choose otherwise |
S3 keeps every object on several devices in at least three Availability Zones, which is where its "eleven nines" of durability come from: 99.999999999%. In practice, files in S3 don't get lost by AWS. They get deleted, overwritten or exposed by people, and the rest of this lesson is about those.
Is it allowed, and what does it cost?
(Your machine)
cd ~/Apps/aws-practice/lesson-15
chmod +x s3-lab.sh
./s3-lab.sh fence
== Is this allowed in us-east-2? (S3 has no dry run, so this reads instead)
S3: allowed
== What each storage class costs to store, per GB a month, in us-east-2 (AWS Price List)
Standard $0.02300
Intelligent-Tiering (frequent tier) $0.02300
Standard-Infrequent Access $0.01250
One Zone-Infrequent Access $0.01000
Glacier Instant Retrieval $0.00400
Glacier Flexible Retrieval $0.00360
Glacier Deep Archive $0.00099
== This lab
a few small files, a few hundred requests: well under 1 cent
the archive-class files are billed for 90 days minimum, even after delete: still a fraction of a cent
Those are straight from AWS's Price List. Deep Archive stores a GB for a twenty-third of Standard's price, and the storage classes section explains the catch. The Price List keeps Deep Archive's storage price under a service code of its own, AmazonS3GlacierDeepArchive; the first version of this script looked only in S3's and picked up a different Deep Archive charge, at $0.021. Reading prices from the API is worth it, and so is checking they make sense.
A bucket, and what AWS set without being asked
In the console: S3 > Buckets > Create bucket. Leave Block all public access ticked, which it is by default, and look at Default encryption and Object Ownership on the way past.
(Your machine)
./s3-lab.sh build
== A bucket: jr-lesson15-b1278e, in us-east-2
== What AWS set without being asked
BlockPublicAcls True
IgnorePublicAcls True
BlockPublicPolicy True
RestrictPublicBuckets True
Encryption AES256
Object ownership BucketOwnerEnforced
Versioning off (never turned on)
== Some files
orders/2026/11/10.csv 43 bytes
recipe.txt 58 bytes
site/images/sourdough.jpg 34 bytes
site/index.html 74 bytes
== The same bucket, listed with / as a separator, the way the console shows it
orders/
site/
recipe.txt
== What S3 keeps about one file
type text/html, 74 bytes, class STANDARD (not stated), encrypted AES256, ETag "8073b0bd689dc6374d0c41a2b5754387"
The script only made the bucket. Everything under "without being asked" is AWS's default for every new bucket since 2023:
| Setting | Means |
|---|---|
| Block Public Access, all four switches | No ACL or bucket policy can make anything in the bucket public, and any that try are refused or ignored |
| Encryption: AES256 | SSE-S3: every object is encrypted on disk with keys S3 manages. Nothing to set, nothing to pay. Lesson 34 uses your own keys instead. |
| BucketOwnerEnforced | ACLs, S3's old per-object permissions, are off. Only policies decide access, and the bucket's account owns every object in it. |
| Versioning: off | An overwrite or delete is final. The versions section turns it on. |
There are no folders
The four files went up with keys like orders/2026/11/10.csv. Listed plainly, they're four keys. Listed with / as a delimiter, which is what the console does, S3 groups them by the text before the first slash, and shows orders/ and site/ as if they were folders. They aren't: there's nothing called orders/ in the bucket, only keys that start with it. "Create folder" in the console makes an empty object whose key ends in a slash, just so the console has something to show.
It matters in two places. Permissions and lifecycle rules use prefixes, like orders/, as their way of saying "this folder". And "renaming a folder" means copying every object under it to a new key and deleting the old one.
The last line is what S3 keeps about each object: its type, size, storage class, encryption, and an ETag, a fingerprint of the contents, used to tell whether a file changed.
Bucket names are unique worldwide
Every bucket name is shared across all of AWS, every account and every Region, because each bucket gets a web address with its name in it: https://jr-lesson15-b1278e.s3.us-east-2.amazonaws.com. Two buckets can't have the same address, so two can't have the same name.
(Your machine)
./s3-lab.sh names
From a second run, with a new bucket:
== Your buckets, as aws s3 ls shows them
2026-11-10 21:43:26 jr-lesson15-89d04e
== Trying to create buckets whose names are already in use
test (BucketAlreadyExists): The requested bucket name is not available. The bucket namespace is shared by all users of the system. Please select a different name and try again.
images (BucketAlreadyExists): The requested bucket name is not available. The bucket namespace is shared by all users of the system. Please select a different name and try again.
jr-lesson15-89d04e (BucketAlreadyOwnedByYou): Your previous request to create the named bucket succeeded and you already own it.
== Names S3 refuses outright
Juniper_Rye (InvalidBucketName): The specified bucket is not valid.
192.168.10.5 (InvalidBucketName): The specified bucket is not valid.
jr (InvalidBucketName): The specified bucket is not valid.
test and images were taken by someone else years ago, and AWS says so: BucketAlreadyExists, "the bucket namespace is shared by all users". Asking again for the lab's own bucket gets a different answer, BucketAlreadyOwnedByYou, so a script can tell "someone else has it" from "I already made it". The last three break the naming rules:
| Rule | Breaks it |
|---|---|
| 3 to 63 characters | jr |
| Lowercase letters, numbers, hyphens and dots only; start and end with a letter or number | Juniper_Rye: capitals and an underscore |
| Not shaped like an IP address | 192.168.10.5 |
| Avoid dots | Allowed, but they break HTTPS on the bucket's address, because the certificate covers only one level of name |
A name can't be changed, and once a bucket is deleted, its name is free for anyone to take. If code, links or other accounts still point at the old name, whoever takes it receives that traffic. That's why the lab adds a random ending, jr-lesson15- plus six characters, and why companies put their own prefix and the account's purpose in every name, like juniperrye-prod-orders.
Everyday bucket commands
The CLI has two ways to talk to S3. aws s3 is the everyday layer: a handful of commands that work like the Linux ones and handle many files at once. aws s3api has one command for every S3 API call, with every option; the lab script uses it where it needs exact control.
aws s3 mb s3://jr-lesson15-b1278e --region us-east-2 # make a bucket
aws s3 ls # list your buckets
aws s3 ls s3://jr-lesson15-b1278e/ --recursive # list every file in one
aws s3 cp recipe.txt s3://jr-lesson15-b1278e/recipe.txt # upload a file
aws s3 cp s3://jr-lesson15-b1278e/recipe.txt . # download it
aws s3 sync ./site s3://jr-lesson15-b1278e/site/ # upload only what changed
aws s3 mv s3://jr-lesson15-b1278e/a.txt s3://jr-lesson15-b1278e/b.txt # rename: a copy, then a delete
aws s3 rm s3://jr-lesson15-b1278e/site/ --recursive # delete everything under a prefix
aws s3 rb s3://jr-lesson15-b1278e --force # delete the bucket and its current files
| Command | Does | Watch out for |
|---|---|---|
mb, make bucket | Creates the bucket | Give --region, or it goes in your profile's |
ls | Lists buckets, or the files under a prefix | Without --recursive it shows one level, like the console |
cp | Copies between your machine and S3, or within S3 | Add --recursive for a whole folder |
sync | Copies only new and changed files | --delete also removes files missing from the source: check with --dryrun first |
mv | Copies, then deletes the original | There's no real rename in S3 |
rm | Deletes files | With versioning on, it only adds delete markers |
rb, remove bucket | Deletes an empty bucket; --force empties it first | --force doesn't remove old versions, so a versioned bucket still won't delete. The take-down section shows why. |
Who can read a file
(Your machine)
./s3-lab.sh perms
== 1. Anyone on the internet, asking for site/index.html
403 AccessDenied
== 2. Try to make the site/ files public with a bucket policy
refused: User: arn:aws:sts::111122223333:assumed-role/AccountFullAccessRole/<your-session> is not authorized to perform: s3:PutBucketPolicy on resource: "the bucket" because public policies are prevented by the BlockPublicPolicy setting in S3 Block Public Access.
== 3. A link to orders/2026/11/10.csv that works for 60 seconds
(not printed: it carries a signature made with your credentials)
HTTPS, straight away: 200: order,item,qty
plain HTTP: 200: order,item,qty
== 4. A bucket policy that refuses anything not over HTTPS
plain HTTP: 403 AccessDenied
HTTPS: 200: order,item,qty
== 5. The same link, after it expires
HTTPS, 70 seconds on: 403 AccessDenied
Five tries, read in order:
| Try | Answer | Why |
|---|---|---|
| 1. Anyone, by the file's address | 403 | Nothing grants it. In AWS, anything not allowed is denied. |
| 2. A bucket policy allowing everyone | Refused | Block Public Access stopped the policy itself, even though your account has every permission. It's a guard above IAM. |
| 3. A presigned link | 200, over HTTPS and HTTP | The link carries your permission, signed, for 60 seconds |
| 4. HTTPS-only policy, then plain HTTP | 403, then 200 over HTTPS | A Deny for requests where aws:SecureTransport is false |
| 5. The link, 70 seconds on | 403 | Expired |
Two kinds of policy, one rule
Lesson 3's IAM policies are attached to a person or role and say what they may do. A bucket policy is attached to the bucket and says who may do what to it, including people from other accounts, or everyone. AWS checks both, with Lesson 3's rule: an explicit deny anywhere wins, then something must allow it, or it's denied.
Try 4 is that rule at work. Your account is allowed everything, but the bucket policy's Deny for plain HTTP beat it. It's a common policy for that reason: a deny can't be outvoted by an allow elsewhere. Lesson 14's bucket policy was the other kind, an Allow for one CloudFront distribution.
Presigned links
A presigned link is an ordinary address with your signature added: who you are, what you may fetch, and when it expires. Anyone holding it can use it until then, with no AWS account. That's why the script never prints it: in a chat or a log, it's a key.
Two things limit it. The expiry you set, up to 7 days. And the credentials that signed it: the lab's came from aws login, a session that lasts up to 12 hours, and the link dies when the session does, whatever expiry you asked for. For links that must last days, a team signs them from a role meant for that.
Plain HTTP worked in try 3 because nothing had said otherwise. Over HTTP, the link, the file and the signature cross the network readable by anyone in between; the HTTPS-only policy is how a bucket refuses that. The Networking track's TLS and HTTPS lesson covers why.
Static websites
S3 can serve a bucket as a website by itself: turn on static website hosting, and the bucket gets a second address that serves index.html for a folder and your own page for errors. Lesson 14 served the shop a different way, with a private bucket behind CloudFront. This section shows S3's own way, and why Lesson 14 didn't use it.
In the console: the bucket > Properties > Static website hosting > Edit > Enable, with the index and error documents. Making it reachable also needs Permissions > Block public access > Edit, and a bucket policy.
(Your machine)
./s3-lab.sh website
From a third run, with a new bucket:
== Turning on website hosting: index.html for folders, site/error.html for missing pages
its address: http://jr-lesson15-a86f10.s3-website.us-east-2.amazonaws.com
== 1. With Block Public Access still on
/site/ 403, S3's own page: Code: AccessDenied
== 2. Lifting the block on this bucket only, then a policy making site/ public
public: site/ only
== 3. The website now
/site/ 200, page: "Juniper & Rye"
/site/croissant.html 404, page: "Sorry, that loaf has sold out"
/orders/2026/11/10.csv 403, page: "Sorry, that loaf has sold out"
the same, over HTTPS curl: (35) Recv failure: Connection reset by peer
== 4. Putting it all back
Block Public Access: all four on
/site/, one last time 404, S3's own page: Code: NoSuchWebsiteConfiguration
The calls behind it:
aws s3api put-bucket-website --bucket jr-lesson15-a86f10 \
--website-configuration '{"IndexDocument": {"Suffix": "index.html"}, "ErrorDocument": {"Key": "site/error.html"}}'
aws s3api put-public-access-block --bucket jr-lesson15-a86f10 --public-access-block-configuration \
BlockPublicAcls=true,IgnorePublicAcls=true,BlockPublicPolicy=false,RestrictPublicBuckets=false
aws s3api put-bucket-policy --bucket jr-lesson15-a86f10 --policy file://site-public.json
aws s3api delete-bucket-website --bucket jr-lesson15-a86f10
| Request | Answer | Why |
|---|---|---|
/site/, block on | 403, S3's page | Hosting alone doesn't make anything public. The website address follows the same permissions as everything else. |
/site/, site public | 200, the shop | A folder address served its index.html: the index document |
/site/croissant.html | 404, the sold-out page | No such file, so the error document, with a 404 |
/orders/...csv | 403, the sold-out page | The policy made only site/ public. The error page is public, so it was shown even for a private file. |
| Over HTTPS | Connection reset | Website addresses only speak HTTP |
/site/, after | 404, NoSuchWebsiteConfiguration | Hosting is off, and the block is back on |
Two details in that table. Lifting the block took only the two policy switches, BlockPublicPolicy and RestrictPublicBuckets; the ACL switches stayed on, so the public policy, covering only site/*, was the one way in. And the missing page got a 404. On the ordinary S3 address, a missing file gets a 403 unless the caller may list the bucket, which is why Lesson 14's /admin was a 403: S3 won't confirm what doesn't exist to someone who can't look. The website address answered 404 here.
S3 hosting or CloudFront?
| S3 website hosting | Private bucket behind CloudFront (Lesson 14) | |
|---|---|---|
| The files | Public: Block Public Access must be lifted | Private: only the distribution may read them |
| HTTPS | No | Yes, with a free certificate |
| Your own name | Only a bucket named exactly like the site, over HTTP | Any name, with an alias record |
index.html in every folder | Built in | Only at the top, unless a small CloudFront Function adds it |
| Speed | One Region | Hundreds of edge locations, with caching |
| WAF | No | Yes |
| Cost for a small site | Pennies | Pennies; CloudFront's free allowance covers most small sites |
For anything real, use CloudFront in front of a private bucket. S3 website hosting still has its place: quick demos, and one trick the exam likes, a bucket whose only job is to redirect, such as juniperandrye-lab.com to www.juniperandrye-lab.com, which needs no public files at all. When a question asks for a static site that is secure, fast or on HTTPS, the answer is CloudFront.
Versions
In the console: the bucket > Properties > Bucket Versioning > Edit > Enable. To see versions, tick Show versions in the bucket's object list.
(Your machine)
./s3-lab.sh versions
== Turning on versioning
== recipe.txt, after two edits
version k0m2ca8DTVQcBZLjyemT16tGcoQMwLUA 58 bytes
version 7M6YABrIFWyNJY5uHVaHbMZYwi4UElom latest 58 bytes
version null 58 bytes
reading it: Sourdough: 520g flour, 360g water, 100g starter, 10g salt
== Deleting it
delete marker OPcsPYe069K9Y.wbSBdYD_RfYe9QBH9R latest 0 bytes
version k0m2ca8DTVQcBZLjyemT16tGcoQMwLUA 58 bytes
version 7M6YABrIFWyNJY5uHVaHbMZYwi4UElom 58 bytes
version null 58 bytes
reading it: (NoSuchKey)
== Bringing it back: delete the delete marker
reading it: Sourdough: 520g flour, 360g water, 100g starter, 10g salt
== And the very first version, by its ID
version null: Sourdough: 500g flour, 350g water, 100g starter, 10g salt
With versioning on, an overwrite doesn't replace the file: it adds a new version, and the old one stays, with its own ID. The recipe went from 500g of flour to 520g, then the water went from 350g to 360g, and all three are kept. The two edits happened in the same second, so the list can't sort them by time; the latest flag is what marks the current one.
A delete doesn't delete anything either. It adds a delete marker, a zero-byte placeholder that becomes the latest version, so reading the file gives NoSuchKey, as if it were gone. Every real version is still underneath. Deleting the marker itself brought the recipe straight back.
The first version's ID is null: it was uploaded before versioning was turned on. Any version can be read by its ID, which is how the lab fetched the original 500g recipe at the end.
The versioning commands
What the versions step ran, by hand:
aws s3api put-bucket-versioning --bucket jr-lesson15-b1278e --versioning-configuration Status=Enabled
aws s3api get-bucket-versioning --bucket jr-lesson15-b1278e
aws s3api list-object-versions --bucket jr-lesson15-b1278e --prefix recipe.txt
aws s3api get-object --bucket jr-lesson15-b1278e --key recipe.txt --version-id null first.txt
aws s3api delete-object --bucket jr-lesson15-b1278e --key recipe.txt
aws s3api delete-object --bucket jr-lesson15-b1278e --key recipe.txt --version-id OPcsPYe069K9Y.wbSBdYD_RfYe9QBH9R
| Command | Does |
|---|---|
put-bucket-versioning ... Status=Enabled | Turns versioning on. Status=Suspended pauses it; there's no "off". |
get-bucket-versioning | Says Enabled or Suspended, or nothing at all if it was never turned on |
list-object-versions --prefix recipe.txt | Every version and delete marker for keys starting with recipe.txt, with their IDs and which is latest |
get-object ... --version-id null | Reads one particular version, here the one uploaded before versioning |
delete-object, no version ID | Adds a delete marker. Nothing is removed. |
delete-object ... --version-id | Permanently deletes that one version. Given the delete marker's ID, it removes the marker, and the file is back. |
The difference between the last two rows is the whole of versioning: without a version ID, a delete is undoable; with one, it's final. In the console, the same split is the Show versions switch: off, Delete adds a marker; on, deleting a ticked version is permanent, and the console makes you type "permanently delete" to do it.
A bucket is always in one of three states:
| State | Uploads and deletes | Existing versions |
|---|---|---|
| Never enabled | Overwrites replace; deletes remove | None; every object's version ID is null |
| Enabled | Every upload is a new version; deletes add markers | All kept |
| Suspended | New uploads get the null ID and replace each other | All still kept, and still billed |
| Without versioning | With versioning | |
|---|---|---|
| Overwrite a file | The old one is gone | The old one is kept |
| Delete a file | Gone | Hidden behind a marker you can remove |
| Storage bill | The current files | Every version of every file |
| Turning it off | Nothing to turn off | Only suspended: existing versions stay |
That third row is why versioning comes with a lifecycle rule, next. For the strictest protection, Object Lock stops anyone, even the account's administrator, deleting a version until a date you set; backups and records kept for the law use it.
Storage classes and lifecycle rules
In the console: choose the class under Properties > Storage class when uploading, or for an existing object > Actions > Edit storage class. Lifecycle rules are under the bucket > Management > Create lifecycle rule.
(Your machine)
./s3-lab.sh classes
== The same small file, stored in five classes
STANDARD stored; read straight away: yes
STANDARD_IA stored; read straight away: yes
GLACIER_IR stored; read straight away: yes
GLACIER refused: an explicit deny in a service control policy (the free plan)
DEEP_ARCHIVE refused: an explicit deny in a service control policy (the free plan)
== Lifecycle rules: the bucket moves and deletes things on a schedule
orders-age-out (orders/, enabled):
after 30 days: move to STANDARD_IA
after 90 days: move to GLACIER_IR
after 2555 days: delete
old-versions (every file, enabled):
old versions: delete 30 days after they stop being current
unfinished uploads: clear away after 7 days
Three classes took the file and handed it straight back. The free plan refused the two archive classes, with an organization-wide rule, a service control policy: the free plan's own fence. Lesson 36 builds rules like it. On a paid plan they're allowed, and the first time this lab ran, the refusal came back as a raw AWS error with the real account ID in it. The script now passes every error through a filter that masks it.
Cheaper to keep, dearer to read
Every class below Standard trades a lower storage price for something else:
| Class | Per GB a month | Minimum billed | To read it back | Fits |
|---|---|---|---|---|
| Standard | $0.023 | None | Free, straight away | Anything used often: the default |
| Intelligent-Tiering | $0.023, falling as files go unread | None; $0.0025 per 1,000 objects a month to watch them | Free, straight away | Files whose use you can't predict |
| Standard-IA (infrequent access) | $0.0125 | 30 days, 128 KB | $0.01 per GB | Files read about once a month |
| One Zone-IA | $0.010 | 30 days, 128 KB | $0.01 per GB | Copies you could recreate: it's in one zone only |
| Glacier Instant Retrieval | $0.004 | 90 days, 128 KB | $0.03 per GB, straight away | Archives read a few times a year |
| Glacier Flexible Retrieval | $0.0036 | 90 days | A restore first: minutes to 12 hours, by speed paid for | Archives you can wait for |
| Glacier Deep Archive | $0.00099 | 180 days | A restore first: 12 to 48 hours | Records kept for years and almost never read |
The two catches are in the middle columns. Minimum durations: delete a Glacier Instant Retrieval file after a week and you're billed for 90 days anyway. Minimum size: a 1 KB file in Standard-IA is billed as 128 KB. So the cheap classes are for large files kept a long time. For a pile of small, short-lived files, Standard is cheaper.
The two archive classes add a third catch: a restore. You ask for a temporary copy, wait between minutes and two days depending on the speed you pay for, and only then can you read it. The lab would have shown a restore request if the free plan allowed the class; the request is restore-object, and the object's Restore field says ongoing-request="true" until the copy is ready.
Lifecycle rules
Moving files between classes by hand doesn't happen. Lifecycle rules do it on a schedule, once a day, with no servers or scripts. The lab's two:
| Rule | Does | Why |
|---|---|---|
orders-age-out, for orders/ | Standard-IA after 30 days, Glacier Instant Retrieval after 90, deleted after 2,555 | Orders are read in their first month, rarely after, and kept for seven years for the accounts |
old-versions, every file | Deletes old versions 30 days after they're replaced | Versioning's undo window, without paying for every version forever |
| Clears unfinished uploads after 7 days | Large files go up in parts; a part-finished upload is billed, and invisible in the object list |
A file uploaded today can't be seen moving, because the first move is 30 days away; the rules are what the bucket will do from now on. Lesson 12 called this kind of rule a behavior policy: it decides what the service does on its own, not who may do what.
Take it down
In the console: the bucket > Empty, type the confirmation, then Delete. Empty removes every version and delete marker, not just the current files.
(Your machine)
./s3-lab.sh delete
== Deleted 9 versions and delete markers
== Deleted bucket jr-lesson15-b1278e
== Left over from this lab
buckets: 0
== Every bucket in the account, with its Region
A bucket must be empty before it can be deleted, and in a versioned bucket, empty means every version and every delete marker. The lab had seven files, but nine things to delete: three ordinary files, the three storage-class copies, and the recipe's three versions. Deleting only the seven current files would have added seven delete markers, and the bucket still wouldn't delete. The script lists versions instead. The last line is empty because the account now has no buckets at all.
By hand: every command the script runs
The same lab without the script, in order. SHOW=1 ./s3-lab.sh build prints the exact calls as they run. (Your machine)
export AWS_PROFILE=juniper-rye AWS_REGION=us-east-2
BUCKET=jr-lesson15-b1278e # yours needs its own ending: names are unique worldwide
# The bucket, and what it was given by default
aws s3api create-bucket --bucket "$BUCKET" --create-bucket-configuration LocationConstraint=us-east-2
aws s3api get-public-access-block --bucket "$BUCKET"
aws s3api get-bucket-encryption --bucket "$BUCKET"
aws s3api get-bucket-ownership-controls --bucket "$BUCKET"
# Files, listed plainly and with a delimiter
aws s3 cp ./files/ "s3://$BUCKET/" --recursive
aws s3api list-objects-v2 --bucket "$BUCKET"
aws s3api list-objects-v2 --bucket "$BUCKET" --delimiter /
aws s3api head-object --bucket "$BUCKET" --key site/index.html
# Permissions: a public policy (refused), a presigned link, an HTTPS-only policy
aws s3api put-bucket-policy --bucket "$BUCKET" --policy file://public.json
LINK=$(aws s3 presign "s3://$BUCKET/orders/2026/11/10.csv" --expires-in 60)
curl -s "$LINK"
aws s3api put-bucket-policy --bucket "$BUCKET" --policy file://https-only.json
# Versions
aws s3api put-bucket-versioning --bucket "$BUCKET" --versioning-configuration Status=Enabled
aws s3api put-object --bucket "$BUCKET" --key recipe.txt --body recipe.txt
aws s3api list-object-versions --bucket "$BUCKET" --prefix recipe.txt
aws s3api delete-object --bucket "$BUCKET" --key recipe.txt # adds a delete marker
aws s3api delete-object --bucket "$BUCKET" --key recipe.txt --version-id "$MARKER" # removes it
aws s3api get-object --bucket "$BUCKET" --key recipe.txt --version-id null first.txt
# Storage classes and lifecycle
aws s3api put-object --bucket "$BUCKET" --key archive/old.csv --body old.csv --storage-class GLACIER_IR
aws s3api put-bucket-lifecycle-configuration --bucket "$BUCKET" --lifecycle-configuration file://lifecycle.json
aws s3api restore-object --bucket "$BUCKET" --key archive/old.csv \
--restore-request 'Days=1,GlacierJobParameters={Tier=Bulk}' # for Glacier Flexible Retrieval or Deep Archive
# Taking it down: every version and marker, then the bucket
aws s3api list-object-versions --bucket "$BUCKET" # build delete.json from Versions and DeleteMarkers
aws s3api delete-objects --bucket "$BUCKET" --delete file://delete.json
aws s3api delete-bucket --bucket "$BUCKET"
aws s3 and aws s3api are both the CLI. aws s3 is the friendly layer, with cp, ls, sync and rb, which work like the Linux commands and handle many files at once. aws s3api is one command per S3 API call, with every option. Scripts that need exact control use s3api.
In real systems
- Block Public Access is also switched on for the whole account, so no new bucket can ever be made public by mistake. Websites are served through CloudFront, as in Lesson 14.
- Versioning plus a lifecycle rule for old versions is the default for anything that matters, often with replication copying every object to a bucket in another Region or account.
- Access is by role, not by person: an application's role is allowed one bucket, or one prefix in it, and nothing else.
- Private subnets reach S3 through a free gateway endpoint (Lesson 13), not a NAT gateway.
- New files can trigger work: an upload to
orders/starts a Lambda function (Lesson 21) through an event notification. - Sensitive data uses keys the team controls, with KMS (Lesson 34), so reading a file needs permission on the key too.
Spot the problem
Work out what's wrong before you read the explanation.
"We delete our old exports every night, and the S3 bill keeps going up." A team's nightly job writes a 20 GB export to a bucket and deletes the one from the night before. The bucket only ever lists one export, yet storage on the bill grows by about 20 GB a day. Versioning is on, because a security review asked for it. What's wrong? Every "deleted" export is still there: with versioning on, the delete added a marker and kept the 20 GB version underneath, every night. The fix: add a lifecycle rule that deletes old versions after a few days, and expired delete markers with them. Then check: after the rule has had a day or two to run, does the bucket's size in S3 Storage Lens, or the bill, stop growing?
Keep this
| Remember | Why |
|---|---|
| Bucket names are worldwide, and freed on delete | Add a prefix and a random ending; never reuse a deleted name others may still use |
| Keys, not folders | Prefixes are how permissions and lifecycle rules say "this folder" |
| Leave Block Public Access on | It stops public policies even from administrators |
| Share files with presigned links | Limited in time, and they expire with the credentials that made them |
| S3 website hosting: public files, HTTP only | For real sites, a private bucket behind CloudFront |
| A deny in a bucket policy wins | HTTPS-only is one line of it |
| Versioning makes deletes undoable | And bills every version, so pair it with a lifecycle rule |
| A delete with a version ID is final | Without one, it only adds a marker |
| Cheap classes have minimums | 30, 90 or 180 days, and 128 KB |
| Archive classes need a restore | Hours, not seconds, and the free plan refuses them |
| Empty means every version | Or the bucket won't delete |
Where you are now
The bakery has a bucket that refused to go public even when asked, a file shared for exactly 60 seconds, a recipe deleted and brought back, three storage classes holding the same file at prices from $0.023 to $0.004 a GB, two the free plan wouldn't allow, and rules that will age the order exports out over seven years. Next, Lesson 16 covers the storage that sits beside a server: EBS disks, EFS shared file systems, and snapshots.
Check yourself
The console shows orders/ like a folder. What is it really?
Another account owns a bucket named test. What happens when you try to create one called test?
Why was the public bucket policy refused, when the account had every permission?
Who can use a presigned link?
The website loaded over HTTP. Why did the same address fail over HTTPS?
With versioning on, the recipe was deleted. What did the delete actually do?
A 10 KB file goes into Glacier Instant Retrieval and is deleted after a week. What's it billed as?
Why does a versioned bucket need a lifecycle rule for old versions?
The bucket held seven files, yet delete removed nine things. Why?
Key terms
- S3 (Simple Storage Service): AWS's object storage.
- Bucket: a container for objects, with a worldwide-unique name, in one Region.
- Bucket namespace: the single list of bucket names shared by every AWS account.
- Object and key: a file, and its full name in the bucket.
- Prefix and delimiter: the start of a key, and the character used to group keys like folders.
- Block Public Access: settings that stop any policy or ACL making a bucket public.
- SSE-S3: encryption with keys S3 manages; on by default.
- Bucket policy: a resource policy, attached to a bucket, saying who may do what to it.
- Presigned link: an address carrying a signed, time-limited permission.
- Static website hosting: S3 serving a bucket as a website, from an HTTP-only website address.
- Index and error documents: the page served for a folder, and the page served when a request fails.
- Versioning: keeping every version of every object.
- Delete marker: what a delete adds in a versioned bucket.
- Storage class: how an object is stored, and so its price, minimums and retrieval rules.
- Restore: a temporary readable copy of an archived object.
- Lifecycle rule: moves or deletes objects on a schedule.
- Object Lock: stops versions being deleted until a set date.
Go deeper
- Networking track: TLS and HTTPS, for why the HTTPS-only policy matters.
- AWS: storage classes (opens in a new tab), S3 pricing (opens in a new tab), and Block Public Access (opens in a new tab).
- AWS: presigned URLs (opens in a new tab), versioning (opens in a new tab), and lifecycle configuration (opens in a new tab).
- Try: run
build, thenaws s3 presigna file with--expires-in 3600and open it in a private browser window. Then make an IAM policy in Lesson 3's style that allowss3:GetObjectonly onarn:aws:s3:::your-bucket/site/*, and use the Policy simulator to check it can readsite/index.htmlbut notorders/. Rundeletewhen you're done.