AWS S3

Amazon S3 (Simple Storage Service) is object storage for files, images, backups, logs, and static assets. It's extremely durable and scales effectively to any volume — but it's object storage, not a filesystem, and using it safely means understanding its access model. Misconfigured S3 buckets are one of the most common sources of public data leaks.

The core idea: you store objects (a file plus metadata) under string keys in buckets, and you control access through IAM and bucket policies. Get the security model right and the rest follows.

TL;DR

Quick Example

Upload and fetch an object with the CLI:

Core Concepts

S3 is strongly consistent for new puts and deletes, but design with distributed behavior in mind for high-scale listing and write patterns.

Security Best Practices

Encryption

Pre-signed URLs

Let clients upload/download directly without exposing AWS keys:

  1. Client requests an upload URL from your backend.
  2. Backend returns a time-limited pre-signed URL.
  3. Client uploads directly to S3.
  4. Backend records the object metadata.

See File Upload.

Versioning & Lifecycle

Events & Integrations

S3 can emit events (e.g. s3:ObjectCreated) to trigger downstream processing. A common pipeline:

This pairs naturally with AWS Lambda and Message Queues.

Performance Tips

Best Practices

Common Mistakes

Accidentally public bucket

Missing CORS for browser uploads

FAQ

Why is S3 "not a filesystem"?

There are no real directories — keys like reports/2026/report.pdf just look hierarchical; the slashes are part of the key string. You can't append to an object in place (you overwrite it), and operations are per-object. Treat it as a flat key→object store with prefix-based listing, not a mounted disk.

How do I let users upload files directly to S3?

Use pre-signed URLs: your backend generates a short-lived URL granting permission for one specific upload, the client PUTs the file straight to S3, then notifies your backend to record metadata. This keeps AWS credentials server-side and offloads bandwidth from your servers. Remember to configure CORS.

Should I use a bucket policy or IAM policy?

Both, for different jobs. IAM policies define what your identities (users, roles) can do across AWS. Bucket policies attach to the bucket and govern access to it specifically (including cross-account or conditional access). For most app access, IAM roles are the primary tool; reach for bucket policies for bucket-level rules.

How do I control S3 storage costs?

Use lifecycle policies to transition infrequently accessed objects to cheaper tiers (S3-IA, Glacier) and expire obsolete data. Enable Intelligent-Tiering for unpredictable access patterns, clean up incomplete multipart uploads, and watch data-transfer/egress charges — fronting public assets with CloudFront often reduces both cost and latency.

Related Topics

References