Storage Services
Store and manage data on AWS — S3 object storage, EBS block storage, EFS shared file systems, and Glacier archival.
Amazon S3
S3 stores objects (files) in buckets. Buckets are globally unique names. Objects have keys (paths), data, and metadata. S3 provides 99.999999999% (11 nines) durability.
Storage classes optimize cost: Standard (frequent access), Intelligent-Tiering (automatic), Standard-IA (infrequent), Glacier Instant Retrieval, Glacier Flexible Retrieval, and Glacier Deep Archive.
- Bucket names must be globally unique across all AWS accounts
- Enable versioning for protection against accidental deletion
- Use lifecycle rules to transition objects to cheaper storage classes
# Create bucket and upload aws s3 mb s3://my-app-assets --region us-east-1 aws s3 cp ./build/ s3://my-app-assets/ --recursive aws s3 sync ./build/ s3://my-app-assets/ --delete # Enable versioning aws s3api put-bucket-versioning \ --bucket my-app-assets \ --versioning-configuration Status=Enabled
EBS Volumes
Elastic Block Store provides persistent block storage for EC2 instances. Volume types: gp3 (general purpose, baseline 3000 IOPS), io2 (high IOPS), st1 (throughput optimized HDD), sc1 (cold HDD).
EBS volumes persist independently of EC2 instance lifecycle. Snapshot volumes to S3 for backup. Copy snapshots across regions for disaster recovery.
# Create and attach EBS volume aws ec2 create-volume \ --availability-zone us-east-1a \ --size 100 --volume-type gp3 --iops 3000 aws ec2 attach-volume \ --volume-id vol-0123456789 \ --instance-id i-0123456789 \ --device /dev/sdf
Amazon EFS
EFS provides scalable, shared file storage for EC2, ECS, and Lambda. Multiple instances mount the same filesystem simultaneously. Automatically scales storage up and down.
Use EFS for content management, web serving, data sharing, and container persistent storage. EFS Infrequent Access reduces cost for rarely accessed files.
# Mount EFS on EC2 sudo mount -t nfs4 \ -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2 \ fs-0123456789.efs.us-east-1.amazonaws.com:/ /mnt/efs
S3 Best Practices
Block public access by default. Use bucket policies and IAM for access control. Enable server-side encryption (SSE-S3 or SSE-KMS). Configure lifecycle rules to transition and expire objects.
Use S3 event notifications to trigger Lambda on uploads. Enable access logging for audit trails. Consider S3 Transfer Acceleration for faster uploads from distant clients.
{
"Rules": [{
"ID": "archive-old-logs",
"Filter": { "Prefix": "logs/" },
"Status": "Enabled",
"Transitions": [{
"Days": 30,
"StorageClass": "STANDARD_IA"
}, {
"Days": 90,
"StorageClass": "GLACIER"
}]
}]
}Storage Selection Guide
S3 for objects: static assets, backups, data lakes, logs. EBS for instance-attached storage: databases, boot volumes, application data. EFS for shared file access across instances. Glacier for long-term archival and compliance.
Most applications use S3 extensively. EBS is required for EC2 boot volumes. EFS fills the niche when multiple instances need shared file access.
# Storage decision matrix # S3: files, images, backups, static websites, data lakes # EBS: database storage, boot volumes, single-instance apps # EFS: shared config, CMS content, container shared storage # Glacier: compliance archives, long-term backups (> 90 days)