☁️Cloud

Bucket

Bucket

A container in cloud object storage. The logical unit for storing files in AWS S3, Google Cloud Storage, and Azure Blob Storage, and a core component of data lakes and backup systems.

📖 Detailed Explanation

A bucket is the top-level container that holds data in cloud object storage. It is similar to the root folder of a file system, but it manages objects (files) in a flat namespace without a hierarchical structure. All object storage services, including AWS S3, Google Cloud Storage, Azure Blob Storage, and MinIO, use the bucket concept.

Buckets became widely adopted with the launch of Amazon S3 in 2006. Unlike traditional file systems, they are accessed over HTTP/HTTPS, and bucket names must be globally unique. Thanks to this design, they provide near-unlimited scalability and 99.999999999% (11 nines) durability.

Objects in a bucket are identified by a key. A path is expressed with slashes, as in "logs/2024/01/app.log", but there is no actual folder structure. This is called a prefix; in the console it looks like a folder, but internally it is flat. Versioning, lifecycle policies, encryption, replication rules, and more can be configured on a bucket.

In practice, buckets are used as the foundation of a data lake, for static website hosting, log archiving, storing machine learning datasets, and backup/recovery systems. In AI/ML workloads, training data and model artifacts are stored in buckets and read directly by SageMaker or Vertex AI.

📊 Performance & Cost

Cost comparison of major cloud object storage services (as of January 2025, Seoul region)

Services Standard storage Archive Data transfer (outbound) Free tier
AWS S3 $0.025/GB $0.004/GB (Glacier) $0.126/GB 5GB, 12 months
GCS $0.023/GB $0.004/GB (Archive) $0.12/GB 5GB, always free
Azure Blob $0.0184/GB $0.002/GB (Archive) $0.138/GB 5GB, 12 months
Cloudflare R2 $0.015/GB - Free 10GB, always free

Cost optimization tip: Set a lifecycle policy that automatically moves data not accessed for 90 days or more to the archive tier. S3 Intelligent-Tiering automatically analyzes access patterns and moves data to the optimal tier.

💻 Code Example

This is an example of AWS S3 bucket operations using Python boto3.

# pip install boto3

import boto3
from botocore.exceptions import ClientError

# S3 클라이언트 생성
s3 = boto3.client('s3', region_name='ap-northeast-2')

# 버킷 생성
bucket_name = 'my-ml-datasets-2024'
try:
    s3.create_bucket(
        Bucket=bucket_name,
        CreateBucketConfiguration={'LocationConstraint': 'ap-northeast-2'}
    )
    print(f"버킷 '{bucket_name}' 생성 완료")
except ClientError as e:
    if e.response['Error']['Code'] == 'BucketAlreadyOwnedByYou':
        print("이미 소유한 버킷입니다")
    else:
        raise

# 버킷에 버저닝 활성화 (중요 데이터 보호)
s3.put_bucket_versioning(
    Bucket=bucket_name,
    VersioningConfiguration={'Status': 'Enabled'}
)

# 파일 업로드 (학습 데이터)
s3.upload_file(
    Filename='train_data.csv',
    Bucket=bucket_name,
    Key='datasets/train/train_data.csv',
    ExtraArgs={'ServerSideEncryption': 'AES256'}  # 서버측 암호화
)

# 대용량 파일 멀티파트 업로드
from boto3.s3.transfer import TransferConfig

config = TransferConfig(
    multipart_threshold=8 * 1024 * 1024,  # 8MB 이상이면 멀티파트
    max_concurrency=10,
    multipart_chunksize=8 * 1024 * 1024
)

s3.upload_file(
    'large_model.tar.gz',
    bucket_name,
    'models/v1/large_model.tar.gz',
    Config=config
)

# 객체 목록 조회 (특정 접두어)
response = s3.list_objects_v2(
    Bucket=bucket_name,
    Prefix='datasets/'
)

for obj in response.get('Contents', []):
    print(f"  {obj['Key']} - {obj['Size']:,} bytes")

# Presigned URL 생성 (임시 다운로드 링크)
url = s3.generate_presigned_url(
    'get_object',
    Params={'Bucket': bucket_name, 'Key': 'datasets/train/train_data.csv'},
    ExpiresIn=3600  # 1시간
)
print(f"다운로드 URL: {url}")

This is a Google Cloud Storage (GCS) example.

# pip install google-cloud-storage

from google.cloud import storage

# 클라이언트 생성 (환경변수 GOOGLE_APPLICATION_CREDENTIALS 설정 필요)
client = storage.Client()

# 버킷 생성
bucket_name = 'my-ml-datasets-2024'
bucket = client.create_bucket(bucket_name, location='asia-northeast3')
print(f"버킷 '{bucket.name}' 생성 완료 (위치: {bucket.location})")

# 수명주기 정책 설정 (90일 후 아카이브)
bucket.add_lifecycle_delete_rule(age=365)  # 365일 후 삭제
bucket.add_lifecycle_set_storage_class_rule(
    'ARCHIVE',
    age=90  # 90일 후 아카이브 티어로 이동
)
bucket.patch()

# 파일 업로드
blob = bucket.blob('datasets/train/train_data.csv')
blob.upload_from_filename('train_data.csv')

# 객체 목록 조회
blobs = client.list_blobs(bucket_name, prefix='datasets/')
for blob in blobs:
    print(f"  {blob.name} - {blob.size:,} bytes")

🗣️ Examples of Practical Conversations

💬 In a Meeting

"If the training data is 500GB, keeping it in S3 Standard costs about $12.50 per month. If we set a lifecycle policy that automatically moves it to Glacier after 90 days, the archive cost drops to $2."

💬 In an Interview

"We built the data lake on S3 buckets. We used a bucket policy to restrict access to a specific VPC only, and enabled server-side encryption (SSE-S3) by default. We keep all API calls in audit logs through CloudTrail."

💬 In a Technical Discussion

"R2 has no egress fees, so it's good as a CDN origin, but it's not 100% compatible with S3. If you need complex bucket policies or event notifications, S3 is still better."

Take a mock interview on this topic → WIA SOOM AI Interview · Start for free

⚠️ Cautions

❌

Leaving Public Access Open

If a bucket is left open to the public, data breaches can occur. Enable S3 Block Public Access at the account level.

❌

Versioning Not Enabled

If you overwrite without versioning, the previous data is permanently deleted. Always enable versioning on buckets that hold important data.

❌

Ignoring Egress Costs

Data transfer (outbound) costs can be higher than storage costs. If large downloads are frequent, consider CloudFront or R2.

✅

The right way

Optimize costs with lifecycle policies, and apply the principle of least privilege with bucket policies. Keep access records with CloudTrail/Cloud Audit Logs, and prepare for disaster recovery with cross-region replication.

🔥 Real-World Incidents

Capital One 2019

Personal data of 100 million people leaked due to S3 bucket permission misconfiguration

Cause: A WAF misconfiguration exposed the system to an SSRF attack; IAM credentials were stolen through EC2 metadata, and the S3 bucket was then accessed

Impact: Personal data of 106 million people (SSN, bank accounts) leaked, $80M fine

Resolution: Enforced IMDSv2, strengthened bucket policies, used VPC endpoints

Lesson: Bucket permissions must strictly follow the principle of least privilege, and EC2 instance metadata service version 2 must be used.

📎 View Details
Twitch 2021

125GB of source code leaked due to an internal Git server misconfiguration

Cause: An internal repository was accidentally exposed externally during a server configuration change

Impact: Entire source code, internal tools, and creator revenue information leaked

Resolution: Rotated all credentials, strengthened access control

Lesson: For repositories containing sensitive data, network isolation is essential so that they are accessible only from inside the VPC.

📎 View Details

📝 Comprehension Quiz

Q1. For an object at the path "logs/2024/01/app.log" in an S3 bucket, what is "logs/2024/"?

Q2. What is the data durability of an S3 bucket?

Q3. Which feature automatically moves data not accessed for 90 days or more to cheaper storage to optimize bucket costs?

🔗 Related Terms

📚 Learn More