S3 Lifecycle Policies and Storage Cost Control
Simulate data aging with storage classes: create a lifecycle rule that transitions and expires objects, verify tiering, and analyze costs with Storage Lens — the core of cost-optimized storage design.
1. S3 → Create bucket: yourname-lifecycle-lab (Block public access ON)
2. Upload 3-5 files of any size (or generate with the CLI below)
3. Note the default storage class: Standard
# Optional: create 5 test files of ~1 MB each and upload
for i in 1 2 3 4 5; do
dd if=/dev/urandom of=test-$i.bin bs=1m count=1
done
aws s3 cp . s3://yourname-lifecycle-lab/ --recursive --exclude "*" --include "test-*"
1. Bucket → Management tab → Create lifecycle rule
2. Name: age-based-tiering, Scope: whole bucket
3. Actions: "Transition current versions of objects between storage classes"
4. Add transition: Standard → Standard-IA after 30 days
5. Add transition: Standard-IA → Glacier Instant Retrieval after 90 days
6. Add transition: Glacier IR → Deep Archive after 365 days
7. Create rule
1. Create a second lifecycle rule: name expire-temp, scope by prefix: temp/
2. Action: "Expire current versions of objects" after 7 days
3. Upload an object to temp/ (e.g., temp/junk.log)
4. Check Management tab → both rules now listed
1. Upload a few MB to temp/ and to the root
2. Bucket → Metrics tab → review Storage class analysis
3. Open S3 Storage Lens (account level) → Free plan dashboard
4. Identify: total storage, objects by storage class, and the "noncurrent" object count
Query the storage class of your objects directly:
aws s3api list-objects-v2 --bucket yourname-lifecycle-lab \
--query "Contents[].[Key,StorageClass,Size]" --output table
1. Delete all objects (select all → Delete, type permanently delete)
2. Delete the lifecycle rules (Management → select rule → Delete)
3. Delete the bucket