AWS Fundamentals

Lesson 3 of 7

S3: Object Storage

S3 (Simple Storage Service) stores files (called objects) inside buckets. It's not a filesystem or a database, it's built for storing and retrieving whole objects (images, backups, static files, logs) at massive scale and very high durability.

Buckets and objects

aws s3 mb s3://my-app-uploads
aws s3 cp photo.jpg s3://my-app-uploads/users/42/photo.jpg
aws s3 ls s3://my-app-uploads/users/42/
  • A bucket name must be globally unique across all of AWS, not just your account.
  • An object key (users/42/photo.jpg) looks like a file path, but S3 has no real folders, it's really just one flat namespace of keys that happens to use / as a visual separator in the console.

Storage classes

Not all data needs to be equally fast to access. S3 offers multiple storage classes with different cost/retrieval-speed tradeoffs:

ClassUse case
StandardFrequently accessed data
Standard-IA (Infrequent Access)Accessed rarely, but needs to be available instantly when it is
GlacierLong-term archives, retrieval takes minutes to hours, much cheaper storage

You can set a lifecycle rule to automatically move objects to a cheaper class (or delete them) after a certain age, e.g. move logs to Glacier after 90 days.

Versioning and static website hosting

Enabling versioning on a bucket keeps every version of an object instead of overwriting it, protecting against accidental deletes/overwrites (at the cost of storing every version).

S3 can also serve static files directly as a website:

aws s3 website s3://my-site --index-document index.html --error-document 404.html

Bucket policies

A bucket policy is a JSON document (using the same policy language as IAM) attached directly to a bucket, controlling who can access it:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": "*",
      "Action": "s3:GetObject",
      "Resource": "arn:aws:s3:::my-site/*"
    }
  ]
}

WARNING

A bucket policy with "Principal": "*" and s3:GetObject makes every object in that bucket publicly readable by anyone on the internet, exactly what you want for a public website's assets, and exactly what you very much don't want for a bucket holding user data or backups. Misconfigured public buckets are one of the most common real-world AWS security incidents.

📝 S3 Quiz

Passing score: 70%
  1. 1.What must be globally unique across all of AWS, not just your account?

  2. 2.S3 has real, nested folders, similar to a traditional filesystem.

  3. 3.An S3 ____ rule can automatically move objects to a cheaper storage class or delete them after a certain age.

  4. 4.Which storage class is meant for long-term archives with retrieval taking minutes to hours?

  5. 5.Enabling versioning on a bucket keeps every version of an object instead of overwriting it.

  6. 6.What does a bucket policy with Principal: * and s3:GetObject do?