Part 16 of Learn AWS from Scratch

S3: Storage Classes and Lifecycle

Not every file deserves the same price. Get to know S3's storage classes from Standard to Deep Archive, when to choose each, how lifecycle rules move your files automatically, and how much you can save on your bill.

In this article
  1. Durability and availability
  2. The classes
  3. Lifecycle
  4. How do you know what to choose?
  5. Hands-on: classes and a lifecycle rule
  6. Summary
  7. Test yourself

In part fifteen we stored everything the default way. But think about your application: a product photo is requested every second, while a five-year-old invoice is opened only during an audit. Why pay the same for both?

Storage classes give you that choice: the less a file is accessed, the less it costs to store, and the more it costs or the longer it takes to retrieve.

Durability and availability

Two terms you need to tell apart:

  • Durability: will the file be lost? 99.999999999% for all classes, noting that classes in a single Availability Zone lose their data if that zone is destroyed.
  • Availability: can you reach it right now? This varies by class, such as 99.99% for Standard.

The classes

Class Suits Retrieval Minimum period Approx. price
Standard Frequently requested data Instant None 0.023
Intelligent-Tiering Unknown access patterns Instant in the automatic tiers None By tier
Standard-IA About once a month Instant, with a retrieval fee 30 days 0.0125
One Zone-IA Data you can recreate Instant, with a fee 30 days 0.01
Glacier Instant Retrieval Once every three months Instant, with a higher fee 90 days 0.004
Glacier Flexible Retrieval Once or twice a year Minutes to hours 90 days 0.0036
Glacier Deep Archive Less than once a year 12 to 48 hours 180 days 0.00099

Prices are in dollars per gigabyte per month, approximate for US Regions, so check the pricing page for yours.

All these classes keep data in three or more Availability Zones, except One Zone-IA. There's also S3 Express One Zone: very high performance with single-digit millisecond latency, in one Availability Zone, using a special type of bucket, at a higher price. It suits analytics and model training that need great speed.

Intelligent-Tiering: when you don't know

If you can't tell how often a file will be requested, this class moves it by itself according to use:

Tier When Retrieval
Frequent Access At the start Instant
Infrequent Access After 30 days without access Instant
Archive Instant Access After 90 days without access Instant
Archive Access Optional, from 90 days Hours
Deep Archive Access Optional, from 180 days Up to 12 hours

You pay a small monitoring fee per object with no retrieval fees, and if a file is requested it returns to the first tier.

Glacier Flexible and Deep Archive: request before reading

In these classes you can't read a file directly. You must first request its restore, choosing a speed:

Class Expedited Standard Bulk
Flexible Retrieval 1 to 5 minutes 3 to 5 hours 5 to 12 hours
Deep Archive Not available 12 hours 48 hours

Lifecycle

You don't need to move files by hand. Lifecycle rules do it automatically according to a file's age. Take an application's logs, for example:

Day 0 Standard Day 30 Standard-IA Day 90 Glacier Flexible Day 365 Deep Archive Day 2555 Delete Cheaper storage; slower, pricier retrieval
A single rule moves the file through the classes as it ages, then deletes it after seven years.

A rule has two kinds of action, and you apply it to a specific prefix or tag:

Action Examples
Transition Move the file to a cheaper class after a number of days
Expiration Delete the file after a period, or old versions, or uploads that never finished

A few things to watch for:

  • Moves only go down the stairs, and the minimum before Standard-IA is 30 days.
  • Files smaller than 128 KB don't move by default, because moving them costs more than it saves.
  • The move itself has a fee per thousand objects, so watch out for millions of small files.

How do you know what to choose?

You don't need to guess. You have tools that read your actual use:

  • Storage Class Analysis: watches access to a prefix or bucket, and suggests when to move from Standard to Standard-IA.
  • Storage Lens: a dashboard across all your accounts: sizes, growth, and buckets with incomplete uploads or no encryption. It has free metrics and paid advanced ones.

If you have millions of files and want to do something to all of them at once, such as changing class or copying, S3 Batch Operations runs it on a list from S3 Inventory, with a report of the results.

On the other side, if you share huge data with another party, Requester Pays has them pay the request and download costs instead of you.

And if you upload millions of small files you won't read one by one, such as logs, bundle them into one archive first. Every PUT is a paid request, so one large upload can cost far less than a million small ones.

Hands-on: classes and a lifecycle rule

We'll carry on with the bucket from the previous part. If your CloudShell session ended, set its name in BUCKET again. Upload a file to a specific class, and check the class:

Bash
echo "monthly report" > report.txt

aws s3 cp report.txt s3://$BUCKET/reports/report.txt --storage-class STANDARD_IA

aws s3api head-object --bucket $BUCKET --key reports/report.txt \
  --query StorageClass

Now add the lifecycle rule from the diagram to the logs/ prefix:

Bash
aws s3api put-bucket-lifecycle-configuration --bucket $BUCKET \
  --lifecycle-configuration '{
  "Rules": [{
    "ID": "logs-rule",
    "Status": "Enabled",
    "Filter": {"Prefix": "logs/"},
    "Transitions": [
      {"Days": 30, "StorageClass": "STANDARD_IA"},
      {"Days": 90, "StorageClass": "GLACIER"},
      {"Days": 365, "StorageClass": "DEEP_ARCHIVE"}
    ],
    "Expiration": {"Days": 2555},
    "AbortIncompleteMultipartUpload": {"DaysAfterInitiation": 7}
  }]
}'

aws s3api get-bucket-lifecycle-configuration --bucket $BUCKET \
  --query "Rules[0].Transitions" --output table

Here's the fun part: upload a file to Glacier and try to read it:

Bash
echo "old invoice" > old.txt
aws s3 cp old.txt s3://$BUCKET/archive/old.txt --storage-class GLACIER

aws s3 cp s3://$BUCKET/archive/old.txt -

It returns an InvalidObjectState error, because the file is stored but can't be read directly. Request a restore:

Bash
aws s3api restore-object --bucket $BUCKET --key archive/old.txt \
  --restore-request '{"Days": 1, "GlacierJobParameters": {"Tier": "Standard"}}'

aws s3api head-object --bucket $BUCKET --key archive/old.txt \
  --query "[StorageClass,Restore]"

You'll see ongoing-request="true". After 3 to 5 hours it becomes false, and a temporary copy is available to read for one day.

Summary

  • The less the access, the lower the storage price, and the higher the cost or time of retrieval.
  • If you don't know the access pattern, Intelligent-Tiering moves files by itself.
  • Watch out for the minimum storage period, the minimum billable size and retrieval fees.
  • Lifecycle rules move and delete files automatically, and always add a rule for incomplete uploads.
  • Storage Lens and Storage Class Analysis let you decide with numbers, not guesses.

Test yourself

Before you move on, try these questions to check you've got this part. Each one is a practical scenario, and the explanation appears once you answer.

Question 1 of 5

A startup is launching a new data platform. Some files may sit untouched for months and then be read heavily, and nobody can predict which. It wants lower storage costs, with no retrieval fees and no rules to maintain. Which class fits?

Show the answer

Correct answer: D

It watches each file's use and moves it between tiers by itself, for a small monitoring fee and with no retrieval fees.

  • A: This charges for every retrieval, so a heavily read file can end up costing more.
  • B: This also charges for retrieval, and keeps data in a single Availability Zone.
  • C: Files here need a restore before reading, which can take hours.

Review: Intelligent-Tiering: when you don't know in this part, and Managing storage costs with Amazon S3 Intelligent-Tiering in the AWS docs.

Question 2 of 5

A video service keeps low-resolution copies of its films, which it can regenerate from the originals at any time. Each is read about once a month and must open instantly. Which class costs the least while meeting this?

Show the answer

Correct answer: B

The copies can be regenerated, so losing them with a zone isn't a disaster, and there's no need to pay for three zones. Retrieval stays instant.

  • A: This works, but at a higher price for protection this data doesn't need.
  • C: A restore here takes 12 to 48 hours.
  • D: Files here need a restore before reading, which takes minutes to hours.

Review: The classes in this part, and Understanding and managing Amazon S3 storage classes in the AWS docs.

Question 3 of 5

A company's application logs must stay instantly readable for 30 days, then be archived cheaply for a year, then be removed. The team doesn't want any scripts to run. What fits?

Show the answer

Correct answer: A

A lifecycle rule moves files to a cheaper class at the age you set and deletes them later, with nothing for you to run.

  • B: This works, but it's code you have to write and maintain.
  • C: This shows you numbers, and doesn't move or delete anything.
  • D: This makes more copies, and neither archives nor removes the originals.

Review: Lifecycle in this part, and Managing the lifecycle of objects in the AWS docs.

Question 4 of 5

An auditor's script tries to read a 20 MB file stored in Glacier Flexible Retrieval, and gets an InvalidObjectState error. The auditor needs the file within 10 minutes. What should the team do?

Show the answer

Correct answer: C

In this class a file has to be restored before it can be read, and Expedited typically makes a file this size available in 1 to 5 minutes.

  • A: A missing permission returns AccessDenied, not this error.
  • B: This is the cheapest option, but it takes 5 to 12 hours.
  • D: Lifecycle moves only go down the stairs, never back up to Standard.

Review: Glacier Flexible and Deep Archive: request before reading in this part, and Understanding archive retrieval options in the AWS docs.

Question 5 of 5

To save money, a team uploaded millions of 10 KB images to Standard-IA. The application reads them all day, and the bill went up. Which two reasons explain this? (Choose two.)

Show the answer

Correct answer: B + C

A 10 KB image is billed as 128 KB in this class, and its low storage price only pays off for data that's rarely read. Data this small and this busy belongs in Standard.

  • A: The monitoring fee belongs to Intelligent-Tiering.
  • D: It costs less per gigabyte, which is why it looks attractive.
  • E: It uses three or more zones just like Standard, so the extra cost doesn't come from there.

Review: The classes in this part, and Understanding and managing Amazon S3 storage classes in the AWS docs.

Your data is now in the right place at the right price, but who can reach it? In part seventeen we cover encryption, signed links and locks against deletion.