AWS from zero · Part 3: Storage and data · Lesson 15 of 38 · about 50 minutes

S3: storage, permissions and lifecycle

Part 3 starts with the storage nearly everything else in AWS leans on. The bakery gets a private bucket and finds out what AWS switches on without being asked, tries to make files public and is stopped, shares a file with a link that dies after 60 seconds, deletes a recipe and gets it back, and learns which storage classes the free plan refuses. Plus lifecycle rules that move and delete files on a schedule. Well under a cent.

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 s3 or aws 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-rye profile from Lesson 4, signed in. Lesson 3's IAM policies come back here, so skim them if they've faded.
  • The script: s3-lab.sh from the practice folder's lesson-15. Everything it creates is named jr-lesson15-*, and its delete step 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=1 in front of any step, such as SHOW=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 names and website steps 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

PartCost
A bucket, its settings and its policies$0
Storing a dozen files under 100 bytes eachA 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 filesBilled as 128 KB for 30 and 90 days, even after delete: still a tiny fraction of a cent
This lessonWell 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.

PartWhat it isIn the bakery
BucketA container, in one Region, with a name no other AWS account in the world is usingjr-lesson15-b1278e; the random ending makes the name unique
ObjectOne file, plus metadata about itA recipe, an order export, a photo
KeyThe object's full name within the bucketorders/2026/11/10.csv
PrefixThe start of a key, used like a folderorders/
Storage classHow the object is stored, and so what it costsStandard, 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)

BASH
cd ~/Apps/aws-practice/lesson-15
chmod +x s3-lab.sh
./s3-lab.sh fence
OUTPUT
== 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)

BASH
./s3-lab.sh build
OUTPUT
== 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:

SettingMeans
Block Public Access, all four switchesNo ACL or bucket policy can make anything in the bucket public, and any that try are refused or ignored
Encryption: AES256SSE-S3: every object is encrypted on disk with keys S3 manages. Nothing to set, nothing to pay. Lesson 34 uses your own keys instead.
BucketOwnerEnforcedACLs, S3's old per-object permissions, are off. Only policies decide access, and the bucket's account owns every object in it.
Versioning: offAn 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)

BASH
./s3-lab.sh names

From a second run, with a new bucket:

OUTPUT
== 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:

RuleBreaks it
3 to 63 charactersjr
Lowercase letters, numbers, hyphens and dots only; start and end with a letter or numberJuniper_Rye: capitals and an underscore
Not shaped like an IP address192.168.10.5
Avoid dotsAllowed, 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.

BASH
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
CommandDoesWatch out for
mb, make bucketCreates the bucketGive --region, or it goes in your profile's
lsLists buckets, or the files under a prefixWithout --recursive it shows one level, like the console
cpCopies between your machine and S3, or within S3Add --recursive for a whole folder
syncCopies only new and changed files--delete also removes files missing from the source: check with --dryrun first
mvCopies, then deletes the originalThere's no real rename in S3
rmDeletes filesWith versioning on, it only adds delete markers
rb, remove bucketDeletes 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)

BASH
./s3-lab.sh perms
OUTPUT
== 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:

TryAnswerWhy
1. Anyone, by the file's address403Nothing grants it. In AWS, anything not allowed is denied.
2. A bucket policy allowing everyoneRefusedBlock Public Access stopped the policy itself, even though your account has every permission. It's a guard above IAM.
3. A presigned link200, over HTTPS and HTTPThe link carries your permission, signed, for 60 seconds
4. HTTPS-only policy, then plain HTTP403, then 200 over HTTPSA Deny for requests where aws:SecureTransport is false
5. The link, 70 seconds on403Expired

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.

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)

BASH
./s3-lab.sh website

From a third run, with a new bucket:

OUTPUT
== 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:

BASH
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
RequestAnswerWhy
/site/, block on403, S3's pageHosting alone doesn't make anything public. The website address follows the same permissions as everything else.
/site/, site public200, the shopA folder address served its index.html: the index document
/site/croissant.html404, the sold-out pageNo such file, so the error document, with a 404
/orders/...csv403, the sold-out pageThe policy made only site/ public. The error page is public, so it was shown even for a private file.
Over HTTPSConnection resetWebsite addresses only speak HTTP
/site/, after404, NoSuchWebsiteConfigurationHosting 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 hostingPrivate bucket behind CloudFront (Lesson 14)
The filesPublic: Block Public Access must be liftedPrivate: only the distribution may read them
HTTPSNoYes, with a free certificate
Your own nameOnly a bucket named exactly like the site, over HTTPAny name, with an alias record
index.html in every folderBuilt inOnly at the top, unless a small CloudFront Function adds it
SpeedOne RegionHundreds of edge locations, with caching
WAFNoYes
Cost for a small sitePenniesPennies; 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)

BASH
./s3-lab.sh versions
OUTPUT
== 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:

BASH
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
CommandDoes
put-bucket-versioning ... Status=EnabledTurns versioning on. Status=Suspended pauses it; there's no "off".
get-bucket-versioningSays Enabled or Suspended, or nothing at all if it was never turned on
list-object-versions --prefix recipe.txtEvery version and delete marker for keys starting with recipe.txt, with their IDs and which is latest
get-object ... --version-id nullReads one particular version, here the one uploaded before versioning
delete-object, no version IDAdds a delete marker. Nothing is removed.
delete-object ... --version-idPermanently 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:

StateUploads and deletesExisting versions
Never enabledOverwrites replace; deletes removeNone; every object's version ID is null
EnabledEvery upload is a new version; deletes add markersAll kept
SuspendedNew uploads get the null ID and replace each otherAll still kept, and still billed
Without versioningWith versioning
Overwrite a fileThe old one is goneThe old one is kept
Delete a fileGoneHidden behind a marker you can remove
Storage billThe current filesEvery version of every file
Turning it offNothing to turn offOnly 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)

BASH
./s3-lab.sh classes
OUTPUT
== 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:

ClassPer GB a monthMinimum billedTo read it backFits
Standard$0.023NoneFree, straight awayAnything used often: the default
Intelligent-Tiering$0.023, falling as files go unreadNone; $0.0025 per 1,000 objects a month to watch themFree, straight awayFiles whose use you can't predict
Standard-IA (infrequent access)$0.012530 days, 128 KB$0.01 per GBFiles read about once a month
One Zone-IA$0.01030 days, 128 KB$0.01 per GBCopies you could recreate: it's in one zone only
Glacier Instant Retrieval$0.00490 days, 128 KB$0.03 per GB, straight awayArchives read a few times a year
Glacier Flexible Retrieval$0.003690 daysA restore first: minutes to 12 hours, by speed paid forArchives you can wait for
Glacier Deep Archive$0.00099180 daysA restore first: 12 to 48 hoursRecords 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:

RuleDoesWhy
orders-age-out, for orders/Standard-IA after 30 days, Glacier Instant Retrieval after 90, deleted after 2,555Orders are read in their first month, rarely after, and kept for seven years for the accounts
old-versions, every fileDeletes old versions 30 days after they're replacedVersioning's undo window, without paying for every version forever
Clears unfinished uploads after 7 daysLarge 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)

BASH
./s3-lab.sh delete
OUTPUT
== 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)

BASH
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

RememberWhy
Bucket names are worldwide, and freed on deleteAdd a prefix and a random ending; never reuse a deleted name others may still use
Keys, not foldersPrefixes are how permissions and lifecycle rules say "this folder"
Leave Block Public Access onIt stops public policies even from administrators
Share files with presigned linksLimited in time, and they expire with the credentials that made them
S3 website hosting: public files, HTTP onlyFor real sites, a private bucket behind CloudFront
A deny in a bucket policy winsHTTPS-only is one line of it
Versioning makes deletes undoableAnd bills every version, so pair it with a lifecycle rule
A delete with a version ID is finalWithout one, it only adds a marker
Cheap classes have minimums30, 90 or 180 days, and 128 KB
Archive classes need a restoreHours, not seconds, and the free plan refuses them
Empty means every versionOr 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

  1. The console shows orders/ like a folder. What is it really?

  2. Another account owns a bucket named test. What happens when you try to create one called test?

  3. Why was the public bucket policy refused, when the account had every permission?

  4. Who can use a presigned link?

  5. The website loaded over HTTP. Why did the same address fail over HTTPS?

  6. With versioning on, the recipe was deleted. What did the delete actually do?

  7. A 10 KB file goes into Glacier Instant Retrieval and is deleted after a week. What's it billed as?

  8. Why does a versioned bucket need a lifecycle rule for old versions?

  9. 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