☁️ Cloud

S3

Simple Storage Service

AWS's object storage. Unlimited scaling, 99.999999999% durability. Supports static web hosting.

📖 Detailed Explanation

Amazon S3 (Simple Storage Service) is an object storage service that AWS launched in 2006, and it is the de facto standard for cloud storage. It guarantees 99.999999999% (11 9s) durability and offers scalability with a maximum single object size of 5 TB and an unlimited number of objects per bucket.

S3's structure consists of buckets and objects. A bucket has a globally unique name, and an object is identified by its Key (path). Although the structure is actually flat, you can use slashes (/) in the Key to make it look like folders.

The storage classes are S3 Standard (frequent access), S3 Intelligent-Tiering (automatic tiering), S3 Standard-IA (infrequent access), S3 One Zone-IA (single AZ), and S3 Glacier Instant/Flexible/Deep Archive (archive). Choosing the appropriate class can reduce costs by up to 95%.

In practice, S3 is used for almost all unstructured data storage, including static web hosting, CDN origins, data lakes, log storage, backups, and ML training data. Integrating with CloudFront enables global content delivery, and integrating with Athena enables data analysis.

💻 Code Example

import boto3
from botocore.config import Config

# S3 클라이언트 생성 (리전별 설정)
s3 = boto3.client('s3',
    region_name='ap-northeast-2',
    config=Config(
        retries={'max_attempts': 3},
        signature_version='s3v4'
    )
)

# 버킷 생성 (서울 리전)
s3.create_bucket(
    Bucket='my-app-files-2024',
    CreateBucketConfiguration={'LocationConstraint': 'ap-northeast-2'}
)

# 파일 업로드 (메타데이터, 암호화 포함)
s3.upload_file(
    Filename='./report.pdf',
    Bucket='my-app-files-2024',
    Key='documents/2024/01/report.pdf',
    ExtraArgs={
        'ContentType': 'application/pdf',
        'ServerSideEncryption': 'AES256',
        'Metadata': {'author': 'kaitrust'}
    }
)

# Presigned URL 생성 (다운로드용, 1시간 유효)
url = s3.generate_presigned_url(
    'get_object',
    Params={
        'Bucket': 'my-app-files-2024',
        'Key': 'documents/2024/01/report.pdf'
    },
    ExpiresIn=3600
)

# Presigned POST (업로드용, 클라이언트 직접 업로드)
presigned_post = s3.generate_presigned_post(
    Bucket='my-app-files-2024',
    Key='uploads/${filename}',
    Conditions=[
        ['content-length-range', 0, 10485760],  # 최대 10MB
        ['starts-with', '$Content-Type', 'image/']
    ],
    ExpiresIn=3600
)

# 멀티파트 업로드 (대용량 파일)
from boto3.s3.transfer import TransferConfig
config = TransferConfig(
    multipart_threshold=100 * 1024 * 1024,  # 100MB 이상시 멀티파트
    max_concurrency=10
)
s3.upload_file('large_file.zip', 'bucket', 'key', Config=config)

🗣️ Say It Like This in Practice

💬 In architecture design
"User profile images are stored in S3 and served through CloudFront. Uploads are sent directly from the client to S3 using a Presigned POST URL, which reduces server load, and thumbnails can be generated automatically with a Lambda trigger."
💬 In a cost optimization discussion
"Our log data is 5 TB per month, and most of it is never queried. If we apply S3 Intelligent-Tiering, data not accessed for 30 days or more is automatically moved to IA, saving 40%. If we move analytics data down to Glacier, we can save more than 90%."
💬 In response to a security audit
"The S3 bucket has Block Public Access fully enabled and is encrypted with SSE-KMS. We apply the principle of least privilege with IAM policies and keep access records with S3 Access Logs and CloudTrail. Versioning is also turned on, so data can be recovered even if it is deleted by mistake."

⚠️ Common Mistakes & Cautions

❌
Public Bucket Exposure

If you accidentally open a bucket to the public, your data is exposed to the whole world. Enable Block Public Access at the account level, and automatically detect public buckets with AWS Config. Since 2023, new buckets are private by default.

❌
Request Cost Explosion

S3 costs are storage capacity + number of requests + data transfer. With many small files, request costs surge. Listing costs also apply, so avoid unnecessary ListObjects calls and reduce origin requests with CloudFront caching.

✅
Optimal Configuration

Enable encryption (SSE-S3 or SSE-KMS), versioning, a Lifecycle Policy, and access logging as the baseline settings. For static web hosting, allow only CloudFront to access the bucket using Origin Access Control (OAC), and avoid exposing direct S3 URLs.

🔗 Related Terms

📚 Learn More