DevDocsDev Docs
S3

AWS S3

Simple Storage Service - Object storage built to retrieve any amount of data

Amazon Simple Storage Service (S3) is an object storage service offering industry-leading scalability, data availability, security, and performance.

Key Facts

S3 offers 99.999999999% (11 9's) durability and stores data across multiple Availability Zones.

Key Concepts

Buckets

Containers for objects. Bucket names must be globally unique across all AWS accounts.

Objects

Files stored in S3, consisting of:

  • Key: The unique identifier (file path)
  • Value: The data (up to 5TB)
  • Metadata: Additional information about the object
  • Version ID: If versioning is enabled

Regions

Buckets are created in specific AWS regions. Choose a region close to your users for lower latency.

Storage Classes

ClassUse CaseAvailability
S3 StandardFrequently accessed data99.99%
S3 Intelligent-TieringUnknown access patterns99.9%
ClassUse CaseAvailability
S3 Standard-IAInfrequent access99.9%
S3 One Zone-IAInfrequent, single AZ99.5%
ClassUse CaseRetrieval Time
S3 Glacier InstantArchive with instant accessMilliseconds
S3 Glacier FlexibleArchive storageMinutes to hours
S3 Glacier Deep ArchiveLong-term archive12-48 hours

Storage Class Lifecycle

Bucket Policies

Control access at the bucket level:

bucket-policy.json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "PublicReadGetObject",
      "Effect": "Allow",
      "Principal": "*",
      "Action": "s3:GetObject",
      "Resource": "arn:aws:s3:::my-bucket/*"
    }
  ]
}

Security Warning

Be extremely careful with public bucket policies. Use AWS Access Analyzer to review bucket access before enabling public access.

Versioning

Keep multiple versions of objects:

Enable Versioning
aws s3api put-bucket-versioning \
  --bucket my-bucket \
  --versioning-configuration Status=Enabled

Once enabled, versioning cannot be disabled—only suspended. All versions are billed as separate objects.

Benefits:

  • Recover from accidental deletions
  • Keep history of object changes
  • Works with lifecycle policies

Lifecycle Rules

Automate object transitions and deletions:

lifecycle-rule.json
{
  "Rules": [
    {
      "ID": "ArchiveOldLogs",
      "Status": "Enabled",
      "Filter": {
        "Prefix": "logs/"
      },
      "Transitions": [
        {
          "Days": 30,
          "StorageClass": "STANDARD_IA"
        },
        {
          "Days": 90,
          "StorageClass": "GLACIER"
        }
      ],
      "Expiration": {
        "Days": 365
      }
    }
  ]
}

Encryption

AWS manages the encryption keys automatically. Simplest option.

Enable Default Encryption (SSE-S3)
aws s3api put-bucket-encryption \
  --bucket my-bucket \
  --server-side-encryption-configuration '{
    "Rules": [{
      "ApplyServerSideEncryptionByDefault": {
        "SSEAlgorithm": "AES256"
      }
    }]
  }'

Use AWS KMS to manage encryption keys. Provides audit trail via CloudTrail.

Enable Default Encryption (SSE-KMS)
aws s3api put-bucket-encryption \
  --bucket my-bucket \
  --server-side-encryption-configuration '{
    "Rules": [{
      "ApplyServerSideEncryptionByDefault": {
        "SSEAlgorithm": "aws:kms",
        "KMSMasterKeyID": "arn:aws:kms:us-east-1:123456789012:key/abc123"
      }
    }]
  }'

Customer provides their own encryption keys. Keys are not stored by AWS.

With SSE-C, you must provide the key with every request. Losing the key means losing access to your data.

Cross-Region Replication

Replicate objects to another region for disaster recovery or compliance:

replication-config.json
{
  "Role": "arn:aws:iam::123456789012:role/replication-role",
  "Rules": [
    {
      "Status": "Enabled",
      "Priority": 1,
      "Filter": {},
      "Destination": {
        "Bucket": "arn:aws:s3:::destination-bucket",
        "StorageClass": "STANDARD"
      }
    }
  ]
}

Versioning must be enabled on both source and destination buckets for replication.

Static Website Hosting

Host static websites directly from S3:

Enable Website Hosting
aws s3 website s3://my-bucket/ \
  --index-document index.html \
  --error-document error.html

Website URL format: http://bucket-name.s3-website-region.amazonaws.com

HTTPS Support

Use CloudFront in front of S3 for HTTPS and custom domain support.

Presigned URLs

Generate temporary URLs for private objects:

Generate Presigned URL
# Valid for 1 hour (3600 seconds)
aws s3 presign s3://my-bucket/my-object.txt --expires-in 3600

Best Practices

Security

  1. Block public access by default
  2. Enable versioning for important data
  3. Use bucket policies and IAM policies together
  4. Enable server-side encryption
  5. Enable access logging

Performance

  1. Use multipart upload for large files (>100MB)
  2. Use S3 Transfer Acceleration for global uploads
  3. Use CloudFront for content delivery
  4. Use appropriate storage classes

Cost Optimization

  1. Use lifecycle policies to transition old data
  2. Monitor with S3 Storage Lens
  3. Delete incomplete multipart uploads
  4. Use S3 Intelligent-Tiering for unknown patterns

Next Steps

On this page