AWS — S3
What is S3?
Simple Storage Service for object storage with high durability.
Create bucket
aws s3 mb s3://my-unique-bucket-name
Upload files
# Single file
aws s3 cp file.txt s3://my-bucket/
# Directory
aws s3 cp ./folder s3://my-bucket/folder --recursive
# Sync directory
aws s3 sync ./folder s3://my-bucket/folder
Download files
aws s3 cp s3://my-bucket/file.txt .
aws s3 sync s3://my-bucket/folder ./folder
List contents
# List buckets
aws s3 ls
# List bucket contents
aws s3 ls s3://my-bucket/
# List with details
aws s3 ls s3://my-bucket/ --recursive --human-readable
Delete
# Delete object
aws s3 rm s3://my-bucket/file.txt
# Delete all objects
aws s3 rm s3://my-bucket/ --recursive
# Delete bucket
aws s3 rb s3://my-bucket
Versioning
# Enable versioning
aws s3api put-bucket-versioning \
--bucket my-bucket \
--versioning-configuration Status=Enabled
# List versions
aws s3api list-object-versions --bucket my-bucket
Lifecycle rules
{
"Rules": [
{
"ID": "Move to Glacier",
"Status": "Enabled",
"Transitions": [
{
"Days": 30,
"StorageClass": "GLACIER"
}
]
}
]
}
CORS configuration
{
"CORSRules": [
{
"AllowedOrigins": ["*"],
"AllowedMethods": ["GET", "PUT"],
"AllowedHeaders": ["*"]
}
]
}
Mini Practice
- Create a bucket
- Upload and download files
- Enable versioning
- Set lifecycle rules
Up Next
Continue with RDS - Managed Databases.
Related Topics
Frequently Asked Questions about S3
What is S3 in AWS?
S3 is a fundamental concept in AWS. This lesson explains it step by step with clear examples, making it easy for beginners to understand.
How do I learn S3?
Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn S3.
Why is S3 important in AWS?
S3 is essential for AWS development. Understanding this concept will help you write better code and solve real-world problems more effectively.