Part 4 of the Core Foundations series.

Amazon S3 (Simple Storage Service) was one of the first AWS services, and it’s still one of the most important. It stores website assets, data lakes, backups, logs, CloudFormation templates and Lambda deployment packages, and it’s where the files for this site live.

The mental model

S3 is object storage, not a file system:

  • A bucket is a container in a Region. Its name must be globally unique across all AWS accounts.
  • An object is a blob of data (up to 5 TB) plus metadata, stored under a key, for example blog/welcome/index.html.
  • There are no real folders. The / in a key is just a character; the console shows prefixes as folders for convenience.

You don’t open, seek and append to objects as you would a file. You PUT a whole object and GET it (or a byte range of it) back. Updating means writing a new version of the whole object.

S3 is designed for 99.999999999% (eleven nines) durability by storing data redundantly across multiple AZs, and it provides strong read-after-write consistency: once a write succeeds, every read sees it.

Storage classes

You pay for storage (per GB-month), requests, and data transfer out. Storage classes trade storage price against access cost and speed:

Class Use it for
S3 Standard Frequently accessed data. The default.
S3 Intelligent-Tiering Data with unknown or changing access patterns; S3 moves objects between tiers for you.
S3 Standard-IA / One Zone-IA Infrequently accessed data that still needs fast retrieval.
S3 Glacier Instant / Flexible Retrieval / Deep Archive Archives, from millisecond access down to retrieval in hours at the lowest price.

Lifecycle rules move objects to cheaper classes as they age, or delete them, for example “move logs to Glacier after 90 days and delete them after a year”.

Protecting data

  • Versioning keeps every version of an object, so an overwrite or delete can be undone. Pair it with a lifecycle rule that expires old versions, or storage grows forever.
  • Encryption at rest is on by default: every new object is encrypted with S3-managed keys (SSE-S3). Use SSE-KMS when you need control over the key and an audit trail of its use.
  • Replication copies objects to another bucket, in the same or another Region.

Access control

Modern S3 defaults are secure, and you should keep them:

  • Block Public Access is enabled on new buckets. Leave it on unless the bucket genuinely must be public, and even then there’s usually a better way (see below).
  • Object ACLs are disabled by default (Object Ownership: bucket owner enforced). Control access with policies instead.

Access is granted through IAM policies on the caller and bucket policies on the bucket. For temporary access to a single private object, generate a presigned URL:

aws s3 presign s3://my-bucket/report.pdf --expires-in 3600

Hands-on: a private static website behind CloudFront

This is how cirruscape.com is served, and it’s a great first S3 project:

  1. Create a bucket with Block Public Access on.
  2. Upload a site: aws s3 sync ./dist s3://my-bucket/.
  3. Create a CloudFront distribution with the bucket as its origin and Origin Access Control (OAC). CloudFront offers to update the bucket policy so only your distribution can read objects.
  4. Browse to the CloudFront domain name. The site loads over HTTPS while the bucket stays private.

Why not use S3’s built-in website hosting? It only serves HTTP and requires a public bucket. CloudFront adds HTTPS, custom domains, caching close to your visitors, and keeps the bucket private.

Gotchas

  • Request costs add up with millions of tiny objects. Batch small items where you can.
  • Deleting a versioned object only adds a delete marker; earlier versions remain (and are billed) until removed.
  • Bucket names are public and permanent-ish. They appear in URLs, and once deleted, a name can be claimed by someone else. Don’t put secrets in them.
  • Data transfer out to the internet is billed. Serving through CloudFront is often cheaper and faster than serving directly from S3.

Wrapping up the series

That’s the four foundations: IAM decides who can do what, VPC decides where things live on the network, EC2 runs servers, and S3 stores data. Next, we’ll build on them with serverless: Lambda, API Gateway and DynamoDB.

← Back to the Core Foundations overview.

← Series overview